-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
dialog_test.go
53 lines (43 loc) · 1.1 KB
/
dialog_test.go
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
49
50
51
52
53
package sipgo
import (
"testing"
"github.com/emiago/sipgo/sip"
"github.com/stretchr/testify/assert"
)
func TestDialogState(t *testing.T) {
inv, _, _ := createTestInvite(t, "sip:nowhere", "udp", "127.0.0.1")
d := Dialog{
InviteRequest: inv,
}
d.Init()
ch := d.StateRead()
ch2 := d.StateRead()
go func() {
d.setState(sip.DialogStateEstablished)
d.setState(sip.DialogStateConfirmed)
d.setState(sip.DialogStateEnded)
}()
assert.Equal(t, sip.DialogStateEstablished, <-ch)
assert.Equal(t, sip.DialogStateConfirmed, <-ch)
assert.Equal(t, sip.DialogStateEnded, <-ch)
assert.Equal(t, sip.DialogStateEstablished, <-ch2)
assert.Equal(t, sip.DialogStateConfirmed, <-ch2)
assert.Equal(t, sip.DialogStateEnded, <-ch2)
}
func BenchmarkDialogSettingState(b *testing.B) {
inv, _, _ := createTestInvite(b, "sip:nowhere", "udp", "127.0.0.1")
d := Dialog{
InviteRequest: inv,
}
d.Init()
mustBeCalled := false
d.OnState(func(s sip.DialogState) {
mustBeCalled = true
})
for i := 0; i < b.N; i++ {
d.setState(sip.DialogStateConfirmed)
}
if !mustBeCalled {
b.Error("On state not called")
}
}