|
1 | 1 | package discover |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "crypto/rand" |
5 | 6 | "errors" |
6 | 7 | "fmt" |
@@ -233,9 +234,6 @@ func TestPortalWireProtocolUdp(t *testing.T) { |
233 | 234 | assert.Equal(t, largeTestContent, data) |
234 | 235 | }() |
235 | 236 | workGroup.Wait() |
236 | | - node1.Stop() |
237 | | - node2.Stop() |
238 | | - node3.Stop() |
239 | 237 | } |
240 | 238 |
|
241 | 239 | func TestPortalWireProtocol(t *testing.T) { |
@@ -375,6 +373,23 @@ func TestPortalWireProtocol(t *testing.T) { |
375 | 373 | node3.Stop() |
376 | 374 | } |
377 | 375 |
|
| 376 | +func TestCancel(t *testing.T) { |
| 377 | + ctx, cancel := context.WithCancel(context.Background()) |
| 378 | + |
| 379 | + go func(ctx context.Context) { |
| 380 | + defer func() { |
| 381 | + t.Log("goroutine cancel") |
| 382 | + }() |
| 383 | + |
| 384 | + time.Sleep(time.Second * 5) |
| 385 | + }(ctx) |
| 386 | + |
| 387 | + cancel() |
| 388 | + t.Log("after main cancel") |
| 389 | + |
| 390 | + time.Sleep(time.Second * 3) |
| 391 | +} |
| 392 | + |
378 | 393 | func TestContentLookup(t *testing.T) { |
379 | 394 | node1, err := setupLocalPortalNode(":17777", nil) |
380 | 395 | assert.NoError(t, err) |
@@ -413,10 +428,6 @@ func TestContentLookup(t *testing.T) { |
413 | 428 | res, _, err = node1.ContentLookup(nonExist, node1.toContentId(nonExist)) |
414 | 429 | assert.Equal(t, ContentNotFound, err) |
415 | 430 | assert.Nil(t, res) |
416 | | - |
417 | | - node1.Stop() |
418 | | - node2.Stop() |
419 | | - node3.Stop() |
420 | 431 | } |
421 | 432 |
|
422 | 433 | func TestTraceContentLookup(t *testing.T) { |
@@ -486,8 +497,4 @@ func TestTraceContentLookup(t *testing.T) { |
486 | 497 | // res, _, err = node1.ContentLookup([]byte{0x2, 0x4}) |
487 | 498 | // assert.Equal(t, ContentNotFound, err) |
488 | 499 | // assert.Nil(t, res) |
489 | | - |
490 | | - node1.Stop() |
491 | | - node2.Stop() |
492 | | - node3.Stop() |
493 | 500 | } |
0 commit comments