You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created a small test to illustrate this, but in summary I have a poller.Wait(5000) on a dealer socket, yes 5 seconds. And a whole lot of responses queued up waiting to be read off. Now I'd expect the messages to all be read off and then when there's been no new messages for 5 seconds the socket returned from the poller.Wait(5000) would be nil. I seem to get a few nil sockets whilst reading the messages, and within 5 seconds of each other.
Code here:
package main
import (
"fmt"
"github.com/zeromq/goczmq"
"testing"
"time"
)
func TestWaitNotWaiting(t *testing.T) {
// create an echo router
router, err := goczmq.NewRouter("tcp://127.0.0.1:9999")
if err != nil {
t.Fatal(err)
}
defer router.Destroy()
// echo all messages received by router back to dealer
go func() {
poller, err := goczmq.NewPoller(router)
if err != nil {
t.Fatal(err)
}
for {
sock := poller.Wait(100)
if sock != nil {
req, err := sock.RecvMessage()
if err != nil {
t.Error("error getting message", err)
}
err = sock.SendMessage(req)
if err != nil {
t.Error("error sending message", err)
}
}
}
}()
dealer, err := goczmq.NewDealer("tcp://127.0.0.1:9999")
if err != nil {
t.Fatal(err)
}
defer dealer.Destroy()
for i := 0; i < 100000; i++ {
err := dealer.SendMessage([][]byte{
[]byte(string(i)),
})
if err != nil {
t.Fatal("error sending message", err)
}
}
poller, err := goczmq.NewPoller(dealer)
if err != nil {
t.Fatal("error setting up poller", err)
}
// now for the fun
for {
sock := poller.Wait(5000) // wait 5 seconds, this is long for illustration purposes.
if sock != nil {
_, err := sock.RecvMessage()
if err != nil {
t.Fatal(err)
}
} else {
fmt.Println("Time", time.Now())
}
}
}
and sample output, first 3 calls very close together and then the wait time appears to be working when nothing is on the queue anymore:
=== RUN TestWaitNotWaiting
Time 2020-04-29 12:58:07.837648709 +0200 SAST m=+0.254047379
Time 2020-04-29 12:58:07.977043834 +0200 SAST m=+0.393442503
Time 2020-04-29 12:58:08.001565177 +0200 SAST m=+0.417963859
Time 2020-04-29 12:58:13.006290839 +0200 SAST m=+5.422689588
Time 2020-04-29 12:58:18.011217611 +0200 SAST m=+10.427616376
The text was updated successfully, but these errors were encountered:
I've created a small test to illustrate this, but in summary I have a poller.Wait(5000) on a dealer socket, yes 5 seconds. And a whole lot of responses queued up waiting to be read off. Now I'd expect the messages to all be read off and then when there's been no new messages for 5 seconds the socket returned from the poller.Wait(5000) would be nil. I seem to get a few nil sockets whilst reading the messages, and within 5 seconds of each other.
Code here:
and sample output, first 3 calls very close together and then the wait time appears to be working when nothing is on the queue anymore:
The text was updated successfully, but these errors were encountered: