Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dda3bfd5b7 |
+8
-1
@@ -16,8 +16,11 @@ func TestAuthManager(t *testing.T) {
|
|||||||
p, envoy := newMockEnvoy(t, WithEmbassyObserver(obs))
|
p, envoy := newMockEnvoy(t, WithEmbassyObserver(obs))
|
||||||
|
|
||||||
signed := []byte(`{"kind":22242}`)
|
signed := []byte(`{"kind":22242}`)
|
||||||
|
var mu sync.Mutex
|
||||||
var calledWith string
|
var calledWith string
|
||||||
callback := func(challenge string) ([]byte, error) {
|
callback := func(challenge string) ([]byte, error) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
calledWith = challenge
|
calledWith = challenge
|
||||||
return signed, nil
|
return signed, nil
|
||||||
}
|
}
|
||||||
@@ -28,7 +31,11 @@ func TestAuthManager(t *testing.T) {
|
|||||||
p.connect()
|
p.connect()
|
||||||
p.receive([]byte(envelope.EncloseAuthChallenge("abc")))
|
p.receive([]byte(envelope.EncloseAuthChallenge("abc")))
|
||||||
|
|
||||||
Eventually(t, func() bool { return calledWith == "abc" },
|
Eventually(t, func() bool {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
return calledWith == "abc"
|
||||||
|
},
|
||||||
"callback not called with challenge")
|
"callback not called with challenge")
|
||||||
|
|
||||||
Eventually(t, func() bool {
|
Eventually(t, func() bool {
|
||||||
|
|||||||
+2
-2
@@ -139,8 +139,6 @@ func (p *EventPublisher) Close() {
|
|||||||
p.wg.Wait()
|
p.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// trySend sends the EVENT envelope. It does not modify entry.sent — callers
|
|
||||||
// are responsible for setting it under p.mu before and/or after this call.
|
|
||||||
func (p *EventPublisher) trySend(entry *pendingEntry) error {
|
func (p *EventPublisher) trySend(entry *pendingEntry) error {
|
||||||
entry.mu.Lock()
|
entry.mu.Lock()
|
||||||
defer entry.mu.Unlock()
|
defer entry.mu.Unlock()
|
||||||
@@ -212,9 +210,11 @@ func (p *EventPublisher) handleEvents() {
|
|||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
var toSend []*pendingEntry
|
var toSend []*pendingEntry
|
||||||
for _, e := range p.pending {
|
for _, e := range p.pending {
|
||||||
|
e.mu.Lock()
|
||||||
if !e.sent {
|
if !e.sent {
|
||||||
toSend = append(toSend, e)
|
toSend = append(toSend, e)
|
||||||
}
|
}
|
||||||
|
e.mu.Unlock()
|
||||||
}
|
}
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -364,7 +364,9 @@ func TestEventPublisher(t *testing.T) {
|
|||||||
}, "Publish did not return a send error")
|
}, "Publish did not return a send error")
|
||||||
|
|
||||||
assert.ErrorContains(t, err, "send failed")
|
assert.ErrorContains(t, err, "send failed")
|
||||||
assert.Len(t, EventsOf[PublishSendFailed](obs), 1)
|
|
||||||
|
// on connect event handler may race with Publish()
|
||||||
|
assert.GreaterOrEqual(t, len(EventsOf[PublishSendFailed](obs)), 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("disconnect then send failure on reconnect", func(t *testing.T) {
|
t.Run("disconnect then send failure on reconnect", func(t *testing.T) {
|
||||||
|
|||||||
+2
-4
@@ -333,15 +333,13 @@ func TestRequestManager_Stream(t *testing.T) {
|
|||||||
p.connect()
|
p.connect()
|
||||||
Eventually(t, envoy.IsConnected, "envoy should be reconnected")
|
Eventually(t, envoy.IsConnected, "envoy should be reconnected")
|
||||||
|
|
||||||
// prevent activate() race between Stream and on-connect handler
|
|
||||||
time.Sleep(20 * time.Millisecond)
|
|
||||||
|
|
||||||
filters := [][]byte{[]byte(`{}`)}
|
filters := [][]byte{[]byte(`{}`)}
|
||||||
id, _, _, err := m.Stream(filters)
|
id, _, _, err := m.Stream(filters)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
Eventually(t, func() bool {
|
Eventually(t, func() bool {
|
||||||
return len(EventsOf[ReqSendFailed](obs)) == 1
|
// on connect event handler may race with Stream()
|
||||||
|
return len(EventsOf[ReqSendFailed](obs)) >= 1
|
||||||
}, "expected ReqSendFailed observable")
|
}, "expected ReqSendFailed observable")
|
||||||
failed := EventsOf[ReqSendFailed](obs)
|
failed := EventsOf[ReqSendFailed](obs)
|
||||||
assert.Equal(t, id, failed[0].SubID)
|
assert.Equal(t, id, failed[0].SubID)
|
||||||
|
|||||||
Reference in New Issue
Block a user