Browse Source

test non persistent mconnection

pull/456/head
Anton Kaliaev 7 years ago
parent
commit
b8a939a894
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 33 additions and 0 deletions
  1. +33
    -0
      connection_test.go

+ 33
- 0
connection_test.go View File

@ -103,3 +103,36 @@ func TestMConnectionStatus(t *testing.T) {
assert.NotNil(status)
assert.Zero(status.Channels[0].SendQueueSize)
}
func TestMConnectionNonPersistent(t *testing.T) {
assert, require := assert.New(t), require.New(t)
server, client := net.Pipe()
defer server.Close()
defer client.Close()
receivedCh := make(chan []byte)
errorsCh := make(chan interface{})
onReceive := func(chID byte, msgBytes []byte) {
receivedCh <- msgBytes
}
onError := func(r interface{}) {
errorsCh <- r
}
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
_, err := mconn.Start()
require.Nil(err)
defer mconn.Stop()
client.Close()
select {
case receivedBytes := <-receivedCh:
t.Fatalf("Expected error, got %v", receivedBytes)
case err := <-errorsCh:
assert.NotNil(err)
assert.False(mconn.IsRunning())
case <-time.After(500 * time.Millisecond):
t.Fatal("Did not receive error in 500ms")
}
}

Loading…
Cancel
Save