Commit 13d7b59
Ferenc Szabo
swarm/network: fix data race in fetcher_test.go
Problem:
Let's say TestA() and TestB() was started right after each other.
TestA() called `go Fetcher.run(ctx)` (read: searchTimeout), on test
completion the context was cancelled, but the test did not wait for
goroutine termination. Test(B) started by modifying searchTimeout
(write).
Solution: Let's just store searchTimeout on the Fetcher struct and
change the package var (default) to const (thread-safe).
Alternative (almost) solution:
The above could have been solved by (little ugly, more complex)
waitGroups. However that would have not work for TestFetcherFactory.
As fetcherFactory.New()starts a goroutine inside it's body without
providing a way for clear termination. (We did not want to modify the
interface for this one, as we think the unclean termination does not
cause a problem in this case in production.)
fixes ethersphere/swarm#11091 parent bad8c1e commit 13d7b59
2 files changed
+16
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
36 | | - | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
| 125 | + | |
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
| |||
232 | 237 | | |
233 | 238 | | |
234 | 239 | | |
235 | | - | |
| 240 | + | |
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
| |||
243 | 248 | | |
244 | 249 | | |
245 | 250 | | |
246 | | - | |
247 | | - | |
| 251 | + | |
| 252 | + | |
248 | 253 | | |
249 | 254 | | |
250 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
287 | 289 | | |
288 | 290 | | |
289 | 291 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 292 | | |
297 | 293 | | |
298 | 294 | | |
| |||
359 | 355 | | |
360 | 356 | | |
361 | 357 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
367 | 361 | | |
368 | 362 | | |
369 | 363 | | |
| |||
0 commit comments