Simplify tests and avoid unnecessary race conditions.
This commit is contained in:
@@ -128,21 +128,13 @@ func setupTestConnection(t *testing.T, config *Config) (
|
||||
|
||||
// Wire WriteMessage to push to outgoingData channel
|
||||
mockSocket.WriteMessageFunc = func(msgType int, data []byte) error {
|
||||
mockSocket.mu.Lock()
|
||||
defer mockSocket.mu.Unlock()
|
||||
|
||||
select {
|
||||
case outgoingData <- mockOutgoingData{msgType: msgType, data: data}:
|
||||
return nil
|
||||
case <-mockSocket.closed:
|
||||
return io.EOF
|
||||
default:
|
||||
select {
|
||||
case outgoingData <- mockOutgoingData{msgType: msgType, data: data}:
|
||||
return nil
|
||||
case <-mockSocket.closed:
|
||||
return io.EOF
|
||||
default:
|
||||
return fmt.Errorf("mock outgoing chanel unavailable")
|
||||
}
|
||||
return fmt.Errorf("mock outgoing chanel unavailable")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user