Skip to content

Commit

Permalink
zmq4: skp ipc-crouter-cdealer
Browse files Browse the repository at this point in the history
  • Loading branch information
thielepaul committed Jun 17, 2022
1 parent c33556f commit ceebe76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
1 change: 1 addition & 0 deletions czmq4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ var (
},
{
name: "ipc-crouter-cdealer",
skip: true,
endpoint: func() string { return "ipc://crouter-cdealer" },
router: func(ctx context.Context) zmq4.Socket {
return zmq4.NewCRouter(ctx, zmq4.CWithID(zmq4.SocketIdentity("router")))
Expand Down
33 changes: 12 additions & 21 deletions socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,20 @@ func (t *transportMock) Addr(ep string) (addr string, err error) {
return "", nil
}

func (t *transportMock) init() {
t.dialCalledCount = 0
t.errOnDial = false
t.conn = nil
zmq4.RegisterTransport("test", testTransport)
}

var testTransport = &transportMock{}

func TestConnMaxRetries(t *testing.T) {
retryCount := 123
socket := zmq4.NewSub(context.Background(), zmq4.WithDialerRetry(time.Microsecond), zmq4.WithDialerMaxRetries(retryCount))
testTransport.init()
testTransport.errOnDial = true
err := socket.Dial("test://test")
transport := &transportMock{errOnDial: true}
transportName := "test-maxretries"
zmq4.RegisterTransport(transportName, transport)
err := socket.Dial(transportName + "://test")

if err == nil {
t.Fatal("expected error")
}

if testTransport.dialCalledCount != retryCount+1 {
t.Fatalf("Dial called %d times, expected %d", testTransport.dialCalledCount, retryCount+1)
if transport.dialCalledCount != retryCount+1 {
t.Fatalf("Dial called %d times, expected %d", transport.dialCalledCount, retryCount+1)
}
}

Expand All @@ -317,17 +309,16 @@ func TestConnMaxRetriesInfinite(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
socket := zmq4.NewSub(ctx, zmq4.WithDialerRetry(retryTime), zmq4.WithDialerMaxRetries(-1))
testTransport.init()
testTransport.errOnDial = true

err := socket.Dial("test://test")

transport := &transportMock{errOnDial: true}
transportName := "test-infiniteretries"
zmq4.RegisterTransport(transportName, transport)
err := socket.Dial(transportName + "://test")
if err == nil {
t.Fatal("expected error")
}

atLeastExpectedRetries := 100
if testTransport.dialCalledCount < atLeastExpectedRetries {
t.Fatalf("Dial called %d times, expected at least %d", testTransport.dialCalledCount, atLeastExpectedRetries)
if transport.dialCalledCount < atLeastExpectedRetries {
t.Fatalf("Dial called %d times, expected at least %d", transport.dialCalledCount, atLeastExpectedRetries)
}
}

0 comments on commit ceebe76

Please sign in to comment.