(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestPubSub_DoesntBlockNotify(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | ctx := testutil.Context(t, testutil.WaitShort) |
| 19 | logger := testutil.Logger(t) |
| 20 | |
| 21 | uut := newWithoutListener(logger, nil) |
| 22 | fListener := newFakePqListener() |
| 23 | uut.pgListener = fListener |
| 24 | go uut.listen() |
| 25 | |
| 26 | cancels := make(chan func()) |
| 27 | go func() { |
| 28 | subCancel, err := uut.Subscribe("bagels", func(ctx context.Context, message []byte) { |
| 29 | t.Logf("got message: %s", string(message)) |
| 30 | }) |
| 31 | assert.NoError(t, err) |
| 32 | cancels <- subCancel |
| 33 | }() |
| 34 | subCancel := testutil.TryReceive(ctx, t, cancels) |
| 35 | cancelDone := make(chan struct{}) |
| 36 | go func() { |
| 37 | defer close(cancelDone) |
| 38 | subCancel() |
| 39 | }() |
| 40 | testutil.TryReceive(ctx, t, cancelDone) |
| 41 | |
| 42 | closeErrs := make(chan error) |
| 43 | go func() { |
| 44 | closeErrs <- uut.Close() |
| 45 | }() |
| 46 | err := testutil.TryReceive(ctx, t, closeErrs) |
| 47 | require.NoError(t, err) |
| 48 | } |
| 49 | |
| 50 | // TestPubSub_DoesntRaceListenUnlisten tests for regressions of |
| 51 | // https://github.com/coder/coder/issues/15312 |
nothing calls this directly
no test coverage detected