mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 14:29:07 +02:00
fix testing tools
This commit is contained in:
@@ -166,24 +166,54 @@ func BuildApiBlackBoxWithDBState(t TB, sqlFile string, expectedPeerUpdate *serve
|
|||||||
return apiHandler, am, done
|
return apiHandler, am, done
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerShouldNotReceiveUpdate(t TB, updateMessage <-chan *server.UpdateMessage) {
|
func peerShouldNotReceiveUpdate(t TB, buffer *server.UpdateBuffer) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
resultCh := make(chan struct {
|
||||||
|
msg *server.UpdateMessage
|
||||||
|
ok bool
|
||||||
|
}, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
msg, ok := buffer.Pop(context.Background())
|
||||||
|
resultCh <- struct {
|
||||||
|
msg *server.UpdateMessage
|
||||||
|
ok bool
|
||||||
|
}{msg, ok}
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case msg := <-updateMessage:
|
case msg := <-resultCh:
|
||||||
t.Errorf("Unexpected message received: %+v", msg)
|
t.Errorf("Unexpected message received: %+v", msg)
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerShouldReceiveUpdate(t TB, updateMessage <-chan *server.UpdateMessage, expected *server.UpdateMessage) {
|
func peerShouldReceiveUpdate(t TB, buffer *server.UpdateBuffer, expected *server.UpdateMessage) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
resultCh := make(chan struct {
|
||||||
|
msg *server.UpdateMessage
|
||||||
|
ok bool
|
||||||
|
}, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
msg, ok := buffer.Pop(context.Background())
|
||||||
|
resultCh <- struct {
|
||||||
|
msg *server.UpdateMessage
|
||||||
|
ok bool
|
||||||
|
}{msg, ok}
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case msg := <-updateMessage:
|
case msg := <-resultCh:
|
||||||
if msg == nil {
|
if msg.msg == nil {
|
||||||
t.Errorf("Received nil update message, expected valid message")
|
t.Errorf("Received nil update message, expected valid message")
|
||||||
}
|
}
|
||||||
|
if !msg.ok {
|
||||||
|
t.Errorf("Expected to receive an update message, but got ok = false")
|
||||||
|
}
|
||||||
assert.Equal(t, expected, msg)
|
assert.Equal(t, expected, msg)
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
t.Errorf("Timed out waiting for update message")
|
t.Errorf("Timed out waiting for update message")
|
||||||
|
|||||||
Reference in New Issue
Block a user