Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for GenServer callbacks in ThousandIsland.Listener #93

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

thymusvulgaris
Copy link
Contributor

Adds unit tests for the following GenServer callbacks in ThousandIsland.Listener:

  • init/1
  • handle_call/3
  • terminate/2

Adds unit tests for the following GenServer callbacks in
ThousandIsland.Listener:

* init/1
* handle_call/3
* terminate/2
@thymusvulgaris
Copy link
Contributor Author

The following CI failure:

 1) test shutdown it should emit telemetry events as expected (ThousandIsland.ServerTest)
Error:      test/thousand_island/server_test.exs:309
     Assertion with ~> failed
     
     Mismatches:
     
       1) List is 3 elements in length, expected 4
     
     code: assert ThousandIsland.TelemetryCollector.get_events(collector_pid)
           ~> [
             {[:thousand_island, :listener, :start], %{monotonic_time: integer()},
              %{
                telemetry_span_context: reference(),
                local_address: {0, 0, 0, 0},
                local_port: integer(),
                transport_module: ThousandIsland.Transports.TCP,
                transport_options: []
              }},
             {[:thousand_island, :acceptor, :start], %{monotonic_time: integer()},
              %{telemetry_span_context: reference(), parent_telemetry_span_context: reference()}},
             {[:thousand_island, :listener, :stop], %{duration: integer(), monotonic_time: integer()},
              %{
                telemetry_span_context: reference(),
                local_address: {0, 0, 0, 0},
                local_port: integer(),
                transport_module: ThousandIsland.Transports.TCP,
                transport_options: []
              }},
             {[:thousand_island, :acceptor, :stop],
              %{connections: 0, duration: integer(), monotonic_time: integer()},
              %{telemetry_span_context: reference(), parent_telemetry_span_context: reference()}}
           ]
     stacktrace:
       test/thousand_island/server_test.exs:325: (test)

..............
Finished in 11.3 seconds (0.00s async, 11.3s sync)
54 tests, 1 failure

was replicated locally by running:

$ for i in {1..10}; do mix test test/thousand_island/server_test.exs >> acceptor.test.log; done

$ cat acceptor.test.log
.............
Finished in 5.5 seconds (0.00s async, 5.5s sync)
13 tests, 0 failures

Randomized with seed 68044
.............
Finished in 5.5 seconds (0.00s async, 5.5s sync)
13 tests, 0 failures

Randomized with seed 835196
.............
Finished in 5.4 seconds (0.00s async, 5.4s sync)
13 tests, 0 failures

Randomized with seed 542935


  1) test shutdown it should emit telemetry events as expected (ThousandIsland.ServerTest)
     test/thousand_island/server_test.exs:309
     Assertion with ~> failed
     
     Mismatches:
     
       1) List is 3 elements in length, expected 4
     
     code: assert ThousandIsland.TelemetryCollector.get_events(collector_pid)
           ~> [
             {[:thousand_island, :listener, :start], %{monotonic_time: integer()},
              %{
                telemetry_span_context: reference(),
                local_address: {0, 0, 0, 0},
                local_port: integer(),
                transport_module: ThousandIsland.Transports.TCP,
                transport_options: []
              }},
             {[:thousand_island, :acceptor, :start], %{monotonic_time: integer()},
              %{telemetry_span_context: reference(), parent_telemetry_span_context: reference()}},
             {[:thousand_island, :listener, :stop], %{duration: integer(), monotonic_time: integer()},
              %{
                telemetry_span_context: reference(),
                local_address: {0, 0, 0, 0},
                local_port: integer(),
                transport_module: ThousandIsland.Transports.TCP,
                transport_options: []
              }},
             {[:thousand_island, :acceptor, :stop],
              %{connections: 0, duration: integer(), monotonic_time: integer()},
              %{telemetry_span_context: reference(), parent_telemetry_span_context: reference()}}
           ]
     stacktrace:
       test/thousand_island/server_test.exs:325: (test)

............
Finished in 5.4 seconds (0.00s async, 5.4s sync)
13 tests, 1 failure

Randomized with seed 195071
.............
Finished in 5.5 seconds (0.00s async, 5.5s sync)
13 tests, 0 failures

Randomized with seed 851493
.............
Finished in 5.4 seconds (0.00s async, 5.4s sync)
13 tests, 0 failures

Randomized with seed 614251
.............
Finished in 5.5 seconds (0.00s async, 5.5s sync)
13 tests, 0 failures

Randomized with seed 268188
.............
Finished in 5.5 seconds (0.00s async, 5.5s sync)
13 tests, 0 failures

Randomized with seed 46400
.............
Finished in 6.0 seconds (0.00s async, 6.0s sync)
13 tests, 0 failures

Randomized with seed 838041
.............
Finished in 5.4 seconds (0.00s async, 5.4s sync)
13 tests, 0 failures

Randomized with seed 197235

@mtrudel
Copy link
Owner

mtrudel commented Oct 26, 2023

Yeah, the telemetry tests in particular are known to be a bit racy.

Looks great!

@mtrudel mtrudel merged commit 976ba7f into mtrudel:main Oct 26, 2023
8 of 9 checks passed
@thymusvulgaris thymusvulgaris deleted the listener-tests branch October 26, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants