2024-01-01 10:16:07 -03:00
|
|
|
package nostr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2024-09-09 13:50:56 +03:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-01-01 10:16:07 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEOSEMadness(t *testing.T) {
|
2024-09-09 13:50:56 +03:30
|
|
|
rl := mustRelayConnect(t, RELAY)
|
2024-01-01 10:16:07 -03:00
|
|
|
defer rl.Close()
|
|
|
|
|
|
|
|
sub, err := rl.Subscribe(context.Background(), Filters{
|
|
|
|
{Kinds: []int{KindTextNote}, Limit: 2},
|
|
|
|
})
|
2024-09-09 13:50:56 +03:30
|
|
|
assert.NoError(t, err)
|
2024-01-01 10:16:07 -03:00
|
|
|
|
|
|
|
timeout := time.After(3 * time.Second)
|
|
|
|
n := 0
|
|
|
|
e := 0
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case event := <-sub.Events:
|
2024-09-09 13:50:56 +03:30
|
|
|
assert.NotNil(t, event)
|
2024-01-01 10:16:07 -03:00
|
|
|
n++
|
|
|
|
case <-sub.EndOfStoredEvents:
|
|
|
|
e++
|
2024-09-09 13:50:56 +03:30
|
|
|
assert.Condition(t, func() (success bool) {
|
|
|
|
return !(e > 1)
|
|
|
|
}, "eose infinite loop")
|
2024-01-01 10:16:07 -03:00
|
|
|
continue
|
|
|
|
case <-rl.Context().Done():
|
|
|
|
t.Fatalf("connection closed: %v", rl.Context().Err())
|
|
|
|
case <-timeout:
|
|
|
|
goto end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2024-09-09 13:50:56 +03:30
|
|
|
assert.Equal(t, 1, e)
|
|
|
|
assert.Condition(t, func() (success bool) {
|
|
|
|
return n >= 2
|
|
|
|
})
|
2024-01-01 10:16:07 -03:00
|
|
|
}
|