Skip to content

Commit c55edd1

Browse files
ttt161ttt161
andauthored
rework tests, fix running time saving (#47)
Co-authored-by: ttt161 <losto@nix>
1 parent 662fee0 commit c55edd1

3 files changed

Lines changed: 24 additions & 28 deletions

File tree

src/prg_notifier.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ serialize_content(Array) when is_list(Array) ->
132132
serialize_content(Arg) ->
133133
erlang:error(badarg, [Arg]).
134134

135-
serialize_timestamp(TimestampSec) ->
136-
Str = calendar:system_time_to_rfc3339(TimestampSec, [{unit, second}, {offset, "Z"}]),
135+
serialize_timestamp(Timestamp) ->
136+
TsMicro = prg_utils:to_microseconds(Timestamp),
137+
Str = calendar:system_time_to_rfc3339(TsMicro, [{unit, microsecond}, {offset, "Z"}]),
137138
erlang:list_to_binary(Str).
138139

139140
%% lifecycle serialization

src/prg_worker.erl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,7 @@ error_and_retry({error, Reason} = Response, TaskHeader, Task, Deadline, State) -
487487
process = #{process_id := ProcessId} = Process,
488488
sidecar_pid = Pid
489489
} = State,
490-
TaskResult = #{
491-
task_id => TaskId,
492-
response => term_to_binary(Response),
493-
finished_time => erlang:system_time(microsecond),
494-
status => <<"error">>
495-
},
490+
TaskResult = task_result(Task, <<"error">>, Response),
496491
_ =
497492
case check_retryable(TaskHeader, Task, RetryPolicy, Reason) of
498493
not_retryable ->

test/prg_base_SUITE.erl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ put_process_with_timeout_test(C) ->
844844
status => <<"running">>,
845845
history => [event(1)]
846846
},
847-
action => #{set_timer => erlang:system_time(second) + 1}
847+
action => #{set_timer => erlang:system_time(microsecond) + 1000000}
848848
},
849849
{ok, ok} = progressor:put(#{ns => ?NS(C), id => Id, args => Args}),
850850
timer:sleep(?AWAIT_TIMEOUT(C)),
@@ -942,7 +942,7 @@ put_process_with_remove_test(C) ->
942942
status => <<"running">>,
943943
history => [event(1)]
944944
},
945-
action => #{set_timer => erlang:system_time(second) + 1, remove => true}
945+
action => #{set_timer => erlang:system_time(microsecond) + 1000000, remove => true}
946946
},
947947
{ok, ok} = progressor:put(#{ns => ?NS(C), id => Id, args => Args}),
948948
timer:sleep(?AWAIT_TIMEOUT(C)),
@@ -987,7 +987,7 @@ mock_processor(simple_timers_test = TestCase) ->
987987
events => [event(1)],
988988
metadata => #{<<"k">> => <<"v">>},
989989
%% postponed timer
990-
action => #{set_timer => erlang:system_time(second) + 2},
990+
action => #{set_timer => erlang:system_time(microsecond) + 2000000},
991991
aux_state => erlang:term_to_binary(<<"aux_state1">>)
992992
},
993993
Self ! 1,
@@ -996,7 +996,7 @@ mock_processor(simple_timers_test = TestCase) ->
996996
Result = #{
997997
events => [event(2)],
998998
%% continuation timer
999-
action => #{set_timer => erlang:system_time(second)},
999+
action => #{set_timer => erlang:system_time(microsecond)},
10001000
aux_state => erlang:term_to_binary(<<"aux_state2">>)
10011001
},
10021002
Self ! 2,
@@ -1017,7 +1017,7 @@ mock_processor(simple_call_test = TestCase) ->
10171017
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
10181018
Result = #{
10191019
events => [event(1)],
1020-
action => #{set_timer => erlang:system_time(second) + 2}
1020+
action => #{set_timer => erlang:system_time(microsecond) + 2000000}
10211021
},
10221022
Self ! 1,
10231023
{ok, Result};
@@ -1047,7 +1047,7 @@ mock_processor(reschedule_after_call_test = TestCase) ->
10471047
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
10481048
Result = #{
10491049
events => [event(1)],
1050-
action => #{set_timer => erlang:system_time(second) + 2}
1050+
action => #{set_timer => erlang:system_time(microsecond) + 2000000}
10511051
},
10521052
Self ! 1,
10531053
{ok, Result};
@@ -1106,7 +1106,7 @@ mock_processor(simple_call_with_range_test = TestCase) ->
11061106
Result = #{
11071107
response => <<"response">>,
11081108
events => [event(6)],
1109-
action => #{set_timer => erlang:system_time(second)}
1109+
action => #{set_timer => erlang:system_time(microsecond)}
11101110
},
11111111
Self ! 3,
11121112
{ok, Result};
@@ -1127,7 +1127,7 @@ mock_processor(call_replace_timer_test = TestCase) ->
11271127
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
11281128
Result = #{
11291129
events => [event(1)],
1130-
action => #{set_timer => erlang:system_time(second) + 2, remove => true}
1130+
action => #{set_timer => erlang:system_time(microsecond) + 2000000, remove => true}
11311131
},
11321132
Self ! 1,
11331133
{ok, Result};
@@ -1136,7 +1136,7 @@ mock_processor(call_replace_timer_test = TestCase) ->
11361136
Result = #{
11371137
response => <<"response">>,
11381138
events => [event(2), event(3)],
1139-
action => #{set_timer => erlang:system_time(second)}
1139+
action => #{set_timer => erlang:system_time(microsecond)}
11401140
},
11411141
Self ! 2,
11421142
{ok, Result};
@@ -1157,7 +1157,7 @@ mock_processor(call_unset_timer_test = TestCase) ->
11571157
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
11581158
Result = #{
11591159
events => [event(1)],
1160-
action => #{set_timer => erlang:system_time(second) + 2}
1160+
action => #{set_timer => erlang:system_time(microsecond) + 2000000}
11611161
},
11621162
Self ! 1,
11631163
{ok, Result};
@@ -1187,15 +1187,15 @@ mock_processor(postponed_call_test = TestCase) ->
11871187
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
11881188
Result = #{
11891189
events => [],
1190-
action => #{set_timer => erlang:system_time(second)}
1190+
action => #{set_timer => erlang:system_time(microsecond)}
11911191
},
11921192
Self ! 1,
11931193
{ok, Result};
11941194
({timeout, <<>>, #{history := []} = _Process}, _Opts, _Ctx) ->
11951195
timer:sleep(3000),
11961196
Result = #{
11971197
events => [event(1)],
1198-
action => #{set_timer => erlang:system_time(second)}
1198+
action => #{set_timer => erlang:system_time(microsecond)}
11991199
},
12001200
Self ! 2,
12011201
{ok, Result};
@@ -1223,7 +1223,7 @@ mock_processor(postponed_call_to_suspended_process_test = TestCase) ->
12231223
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
12241224
Result = #{
12251225
events => [],
1226-
action => #{set_timer => erlang:system_time(second)}
1226+
action => #{set_timer => erlang:system_time(microsecond)}
12271227
},
12281228
Self ! 1,
12291229
{ok, Result};
@@ -1271,7 +1271,7 @@ mock_processor(simple_repair_after_non_retriable_error_test = TestCase) ->
12711271
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
12721272
Result = #{
12731273
events => [],
1274-
action => #{set_timer => erlang:system_time(second)}
1274+
action => #{set_timer => erlang:system_time(microsecond)}
12751275
},
12761276
Self ! 1,
12771277
{ok, Result};
@@ -1282,7 +1282,7 @@ mock_processor(simple_repair_after_non_retriable_error_test = TestCase) ->
12821282
%% timeout via simple repair
12831283
Result = #{
12841284
events => [event(1)],
1285-
action => #{set_timer => erlang:system_time(second)}
1285+
action => #{set_timer => erlang:system_time(microsecond)}
12861286
},
12871287
Self ! 3,
12881288
{ok, Result};
@@ -1302,7 +1302,7 @@ mock_processor(repair_after_non_retriable_error_test = TestCase) ->
13021302
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
13031303
Result = #{
13041304
events => [],
1305-
action => #{set_timer => erlang:system_time(second)}
1305+
action => #{set_timer => erlang:system_time(microsecond)}
13061306
},
13071307
Self ! 1,
13081308
{ok, Result};
@@ -1331,7 +1331,7 @@ mock_processor(error_after_max_retries_test = TestCase) ->
13311331
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
13321332
Result = #{
13331333
events => [],
1334-
action => #{set_timer => erlang:system_time(second)}
1334+
action => #{set_timer => erlang:system_time(microsecond)}
13351335
},
13361336
Self ! 1,
13371337
{ok, Result};
@@ -1391,7 +1391,7 @@ mock_processor(remove_by_timer_test = TestCase) ->
13911391
MockProcessor = fun({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
13921392
Result = #{
13931393
events => [event(1), event(2)],
1394-
action => #{set_timer => erlang:system_time(second) + 2, remove => true}
1394+
action => #{set_timer => erlang:system_time(microsecond) + 2000000, remove => true}
13951395
},
13961396
{ok, Result}
13971397
end,
@@ -1403,7 +1403,7 @@ mock_processor(remove_without_timer_test = TestCase) ->
14031403
({init, <<"init_args">>, _Process}, _Opts, _Ctx) ->
14041404
Result = #{
14051405
events => [event(1)],
1406-
action => #{set_timer => erlang:system_time(second) + 2}
1406+
action => #{set_timer => erlang:system_time(microsecond) + 2000000}
14071407
},
14081408
Self ! 1,
14091409
{ok, Result};
@@ -1471,7 +1471,7 @@ expect_steps_counter(ExpectedSteps, CurrentStep) ->
14711471
event(Id) ->
14721472
#{
14731473
event_id => Id,
1474-
timestamp => erlang:system_time(second),
1474+
timestamp => erlang:system_time(microsecond),
14751475
metadata => #{<<"format_version">> => 1},
14761476
%% msg_pack compatibility for kafka
14771477
payload => erlang:term_to_binary({bin, crypto:strong_rand_bytes(8)})

0 commit comments

Comments
 (0)