(t *testing.T)
| 1574 | } |
| 1575 | |
| 1576 | func TestTerminateAndWaitForClose(t *testing.T) { |
| 1577 | LongRunningTest(t) |
| 1578 | |
| 1579 | SetUpTestLogging(t, LevelInfo, KeySGTest) |
| 1580 | |
| 1581 | tests := []struct { |
| 1582 | name string |
| 1583 | terminator chan struct{} |
| 1584 | done chan struct{} |
| 1585 | fn func(ctx context.Context, terminator chan struct{}, done chan struct{}) |
| 1586 | timeout time.Duration |
| 1587 | wantErr bool |
| 1588 | }{ |
| 1589 | { |
| 1590 | name: "terminate and done immediate", |
| 1591 | terminator: make(chan struct{}), |
| 1592 | done: make(chan struct{}), |
| 1593 | fn: func(ctx context.Context, t chan struct{}, d chan struct{}) { |
| 1594 | <-t |
| 1595 | InfofCtx(ctx, KeySGTest, "got t closing d") |
| 1596 | close(d) |
| 1597 | }, |
| 1598 | timeout: time.Millisecond * 100, |
| 1599 | wantErr: false, |
| 1600 | }, |
| 1601 | { |
| 1602 | name: "terminate and done within timeout", |
| 1603 | terminator: make(chan struct{}), |
| 1604 | done: make(chan struct{}), |
| 1605 | fn: func(ctx context.Context, t chan struct{}, d chan struct{}) { |
| 1606 | <-t |
| 1607 | InfofCtx(ctx, KeySGTest, "got t waiting to close d") |
| 1608 | select { |
| 1609 | case <-time.After(time.Millisecond * 100): |
| 1610 | InfofCtx(ctx, KeySGTest, "closing d") |
| 1611 | close(d) |
| 1612 | case <-ctx.Done(): |
| 1613 | InfofCtx(ctx, KeySGTest, "test context done") |
| 1614 | } |
| 1615 | }, |
| 1616 | timeout: time.Second * 10, |
| 1617 | wantErr: false, |
| 1618 | }, |
| 1619 | { |
| 1620 | name: "terminate and done after timeout", |
| 1621 | terminator: make(chan struct{}), |
| 1622 | done: make(chan struct{}), |
| 1623 | fn: func(ctx context.Context, t chan struct{}, d chan struct{}) { |
| 1624 | <-t |
| 1625 | InfofCtx(ctx, KeySGTest, "got t waiting to close d") |
| 1626 | select { |
| 1627 | case <-time.After(time.Second * 10): |
| 1628 | InfofCtx(ctx, KeySGTest, "closing d") |
| 1629 | close(d) |
| 1630 | case <-ctx.Done(): |
| 1631 | InfofCtx(ctx, KeySGTest, "test context done") |
| 1632 | } |
| 1633 | }, |
nothing calls this directly
no test coverage detected