Skip to content

Commit

Permalink
Finish CT
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Feb 27, 2023
1 parent efda349 commit 8840519
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions test/router_ics_gateway_location_worker_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
main_test/1
]).

-record(location, {
gateway :: libp2p_crypto:pubkey_bin(),
timestamp :: non_neg_integer(),
h3_index :: h3:index()
}).

%%--------------------------------------------------------------------
%% COMMON TEST CALLBACK FUNCTIONS
%%--------------------------------------------------------------------
Expand Down Expand Up @@ -70,18 +76,33 @@ end_per_testcase(TestCase, Config) ->
%%--------------------------------------------------------------------

main_test(_Config) ->
timer:sleep(5000),
#{public := PubKey1} = libp2p_crypto:generate_keys(ecc_compact),
PubKeyBin1 = libp2p_crypto:pubkey_to_bin(PubKey1),
ExpectedIndex = h3:from_string("8828308281fffff"),

Before = erlang:system_time(millisecond),

%% Let worker start
test_utils:wait_until(fun() ->
erlang:is_pid(erlang:whereis(router_ics_gateway_location_worker))
try router_ics_gateway_location_worker:get(PubKeyBin1) of
{ok, ExpectedIndex} -> true;
_ -> false
catch
_:_ ->
false
end
end),

#{public := PubKey1} = libp2p_crypto:generate_keys(ecc_compact),
PubKeyBin1 = libp2p_crypto:pubkey_to_bin(PubKey1),
[LocationRec] = ets:lookup(router_ics_gateway_location_worker_ets, PubKeyBin1),

?assertEqual(
{ok, h3:from_string("8828308281fffff")}, router_ics_gateway_location_worker:get(PubKeyBin1)
),
?assertEqual(PubKeyBin1, LocationRec#location.gateway),
?assertEqual(ExpectedIndex, LocationRec#location.h3_index),

Timestamp = LocationRec#location.timestamp,
Now = erlang:system_time(millisecond),

?assert(Timestamp > Before),
?assert(Timestamp =< Now),

[{location, Req1}] = rcv_loop([]),
?assertEqual(PubKeyBin1, Req1#iot_config_gateway_location_req_v1_pb.gateway),
Expand Down

0 comments on commit 8840519

Please sign in to comment.