-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop_shutdown_internal_test.go
More file actions
36 lines (29 loc) · 958 Bytes
/
Copy pathstop_shutdown_internal_test.go
File metadata and controls
36 lines (29 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package controls
import (
"context"
"testing"
"time"
)
// TestStop_ReturnsAfterShutdownComplete proves F2: if the shutdown sequence has
// already completed (shutdownComplete closed) between the CAS and the channel
// send, Stop() must not block forever on the unbuffered message channel whose
// receiver has gone. This white-box test forces exactly that interleaving.
func TestStop_ReturnsAfterShutdownComplete(t *testing.T) {
t.Parallel()
c := NewController(context.Background())
// Simulate: caller A won the CAS (Running), then the full shutdown ran and
// the message processor exited before A's send.
c.SetState(Running)
close(c.shutdownComplete)
done := make(chan struct{})
go func() {
c.Stop()
close(done)
}()
select {
case <-done:
// Stop returned promptly — the send was guarded on shutdownComplete.
case <-time.After(2 * time.Second):
t.Fatal("Stop() hung on a message-channel send after shutdown completed")
}
}