-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_turn_host_test.go
More file actions
48 lines (41 loc) · 1.02 KB
/
stream_turn_host_test.go
File metadata and controls
48 lines (41 loc) · 1.02 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
package agentremote
import (
"testing"
"time"
)
type testHostAborterState struct {
id string
aborted string
}
func (s *testHostAborterState) Abort(reason string) {
s.aborted = reason
}
func TestStreamTurnHostDrainAndAbortGetsAbortersOutsideLock(t *testing.T) {
var host *StreamTurnHost[testHostAborterState]
state := &testHostAborterState{id: "turn-1"}
host = NewStreamTurnHost(StreamTurnHostCallbacks[testHostAborterState]{
GetAborter: func(state *testHostAborterState) Aborter {
_ = host.IsActive(state.id)
return state
},
})
host.Lock()
host.SetLocked(state.id, state)
host.Unlock()
done := make(chan struct{})
go func() {
host.DrainAndAbort("disconnect")
close(done)
}()
select {
case <-done:
case <-time.After(200 * time.Millisecond):
t.Fatal("DrainAndAbort blocked while collecting aborters")
}
if state.aborted != "disconnect" {
t.Fatalf("expected abort reason to propagate, got %q", state.aborted)
}
if host.IsActive(state.id) {
t.Fatal("expected state to be removed after drain")
}
}