|
@ -32,8 +32,16 @@ func TestMConnectionSend(t *testing.T) { |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
|
|
|
|
|
|
server, client := netPipe() |
|
|
server, client := netPipe() |
|
|
defer server.Close() |
|
|
|
|
|
defer client.Close() |
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := server.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := client.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
mconn := createTestMConnection(client) |
|
|
mconn := createTestMConnection(client) |
|
|
_, err := mconn.Start() |
|
|
_, err := mconn.Start() |
|
@ -44,12 +52,18 @@ func TestMConnectionSend(t *testing.T) { |
|
|
assert.True(mconn.Send(0x01, msg)) |
|
|
assert.True(mconn.Send(0x01, msg)) |
|
|
// Note: subsequent Send/TrySend calls could pass because we are reading from
|
|
|
// Note: subsequent Send/TrySend calls could pass because we are reading from
|
|
|
// the send queue in a separate goroutine.
|
|
|
// the send queue in a separate goroutine.
|
|
|
server.Read(make([]byte, len(msg))) |
|
|
|
|
|
|
|
|
_, err = server.Read(make([]byte, len(msg))) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
assert.True(mconn.CanSend(0x01)) |
|
|
assert.True(mconn.CanSend(0x01)) |
|
|
|
|
|
|
|
|
msg = "Spider-Man" |
|
|
msg = "Spider-Man" |
|
|
assert.True(mconn.TrySend(0x01, msg)) |
|
|
assert.True(mconn.TrySend(0x01, msg)) |
|
|
server.Read(make([]byte, len(msg))) |
|
|
|
|
|
|
|
|
_, err = server.Read(make([]byte, len(msg))) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
assert.False(mconn.CanSend(0x05), "CanSend should return false because channel is unknown") |
|
|
assert.False(mconn.CanSend(0x05), "CanSend should return false because channel is unknown") |
|
|
assert.False(mconn.Send(0x05, "Absorbing Man"), "Send should return false because channel is unknown") |
|
|
assert.False(mconn.Send(0x05, "Absorbing Man"), "Send should return false because channel is unknown") |
|
@ -59,8 +73,16 @@ func TestMConnectionReceive(t *testing.T) { |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
|
|
|
|
|
|
server, client := netPipe() |
|
|
server, client := netPipe() |
|
|
defer server.Close() |
|
|
|
|
|
defer client.Close() |
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := server.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := client.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
receivedCh := make(chan []byte) |
|
|
receivedCh := make(chan []byte) |
|
|
errorsCh := make(chan interface{}) |
|
|
errorsCh := make(chan interface{}) |
|
@ -97,8 +119,16 @@ func TestMConnectionStatus(t *testing.T) { |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
|
|
|
|
|
|
server, client := netPipe() |
|
|
server, client := netPipe() |
|
|
defer server.Close() |
|
|
|
|
|
defer client.Close() |
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := server.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := client.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
mconn := createTestMConnection(client) |
|
|
mconn := createTestMConnection(client) |
|
|
_, err := mconn.Start() |
|
|
_, err := mconn.Start() |
|
@ -114,8 +144,16 @@ func TestMConnectionStopsAndReturnsError(t *testing.T) { |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
assert, require := assert.New(t), require.New(t) |
|
|
|
|
|
|
|
|
server, client := netPipe() |
|
|
server, client := netPipe() |
|
|
defer server.Close() |
|
|
|
|
|
defer client.Close() |
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := server.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err := client.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
receivedCh := make(chan []byte) |
|
|
receivedCh := make(chan []byte) |
|
|
errorsCh := make(chan interface{}) |
|
|
errorsCh := make(chan interface{}) |
|
@ -130,7 +168,9 @@ func TestMConnectionStopsAndReturnsError(t *testing.T) { |
|
|
require.Nil(err) |
|
|
require.Nil(err) |
|
|
defer mconn.Stop() |
|
|
defer mconn.Stop() |
|
|
|
|
|
|
|
|
client.Close() |
|
|
|
|
|
|
|
|
if err := client.Close(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
select { |
|
|
select { |
|
|
case receivedBytes := <-receivedCh: |
|
|
case receivedBytes := <-receivedCh: |
|
|