-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheose_test.go
More file actions
47 lines (40 loc) · 819 Bytes
/
eose_test.go
File metadata and controls
47 lines (40 loc) · 819 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
37
38
39
40
41
42
43
44
45
46
47
package nostr
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestEOSEMadness(t *testing.T) {
rl := mustRelayConnect(t, RELAY)
defer rl.Close()
sub, err := rl.Subscribe(context.Background(), Filters{
{Kinds: []int{KindTextNote}, Limit: 2},
})
assert.NoError(t, err)
timeout := time.After(3 * time.Second)
n := 0
e := 0
for {
select {
case event := <-sub.Events:
assert.NotNil(t, event)
n++
case <-sub.EndOfStoredEvents:
e++
assert.Condition(t, func() (success bool) {
return !(e > 1)
}, "eose infinite loop")
continue
case <-rl.Context().Done():
t.Fatalf("connection closed: %v", rl.Context().Err())
case <-timeout:
goto end
}
}
end:
assert.Equal(t, 1, e)
assert.Condition(t, func() (success bool) {
return n >= 2
})
}