Commit 18e9a7a
authored
chore(sync-service): Fix flakey Publisher tests (#2851)
These tests can occasionally fail with:
```
Assertion failed, no matching message after 5000ms
The process mailbox is empty.
code: assert_receive :publish_finished
```
The race condition occurs if the TestSubscriber receives the
`:finish_processing_message` message before it receives the publisher
call, in which case it swallows the message since `handle_info` is not
implemented on TestSubscriber. A GenServer would log that a message had
been received and not handled, but as `use GenServer` was omitted from
the TestSubscriber the message was swallowed silently.
This PR:
- Adds `use GenServer` to the TestSubscriber as this is best practice
(the race condition would have been obvious had it been included in the
first place)
- Waits for `:message_received` from each of the subscribers before
sending `:finish_processing_message`. This eliminates the race
condition.
- Renames `event` to `message` for consistency
Credit to ChatGPT which worked out what the race condition was. It's
solution was terrible, but the hard part was knowing what the race
condition was, so that was super helpful.1 parent 970431a commit 18e9a7a
1 file changed
+29
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | | - | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
51 | 58 | | |
52 | | - | |
| 59 | + | |
53 | 60 | | |
54 | | - | |
55 | | - | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
59 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | | - | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | | - | |
66 | | - | |
| 76 | + | |
| 77 | + | |
67 | 78 | | |
68 | 79 | | |
69 | 80 | | |
| |||
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
75 | 89 | | |
76 | 90 | | |
77 | 91 | | |
78 | 92 | | |
79 | | - | |
80 | | - | |
| 93 | + | |
| 94 | + | |
81 | 95 | | |
82 | 96 | | |
83 | 97 | | |
0 commit comments