|
@@ -31,10 +31,10 @@ func TestPing(t *testing.T) {
|
|
|
ar, aw := io.Pipe()
|
|
|
br, bw := io.Pipe()
|
|
|
|
|
|
- c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c0 := getRawConnection(NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c0.Start()
|
|
|
defer closeAndWait(c0, ar, bw)
|
|
|
- c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c1 := getRawConnection(NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c1.Start()
|
|
|
defer closeAndWait(c1, ar, bw)
|
|
|
c0.ClusterConfig(ClusterConfig{})
|
|
@@ -57,10 +57,10 @@ func TestClose(t *testing.T) {
|
|
|
ar, aw := io.Pipe()
|
|
|
br, bw := io.Pipe()
|
|
|
|
|
|
- c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c0 := getRawConnection(NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c0.Start()
|
|
|
defer closeAndWait(c0, ar, bw)
|
|
|
- c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionAlways)
|
|
|
+ c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionAlways, nil)
|
|
|
c1.Start()
|
|
|
defer closeAndWait(c1, ar, bw)
|
|
|
c0.ClusterConfig(ClusterConfig{})
|
|
@@ -102,7 +102,7 @@ func TestCloseOnBlockingSend(t *testing.T) {
|
|
|
m := newTestModel()
|
|
|
|
|
|
rw := testutils.NewBlockingRW()
|
|
|
- c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c := getRawConnection(NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c.Start()
|
|
|
defer closeAndWait(c, rw)
|
|
|
|
|
@@ -153,10 +153,10 @@ func TestCloseRace(t *testing.T) {
|
|
|
ar, aw := io.Pipe()
|
|
|
br, bw := io.Pipe()
|
|
|
|
|
|
- c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionNever).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c0 := getRawConnection(NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionNever, nil))
|
|
|
c0.Start()
|
|
|
defer closeAndWait(c0, ar, bw)
|
|
|
- c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionNever)
|
|
|
+ c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionNever, nil)
|
|
|
c1.Start()
|
|
|
defer closeAndWait(c1, ar, bw)
|
|
|
c0.ClusterConfig(ClusterConfig{})
|
|
@@ -193,7 +193,7 @@ func TestClusterConfigFirst(t *testing.T) {
|
|
|
m := newTestModel()
|
|
|
|
|
|
rw := testutils.NewBlockingRW()
|
|
|
- c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c := getRawConnection(NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c.Start()
|
|
|
defer closeAndWait(c, rw)
|
|
|
|
|
@@ -245,7 +245,7 @@ func TestCloseTimeout(t *testing.T) {
|
|
|
m := newTestModel()
|
|
|
|
|
|
rw := testutils.NewBlockingRW()
|
|
|
- c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c := getRawConnection(NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c.Start()
|
|
|
defer closeAndWait(c, rw)
|
|
|
|
|
@@ -865,7 +865,7 @@ func TestClusterConfigAfterClose(t *testing.T) {
|
|
|
m := newTestModel()
|
|
|
|
|
|
rw := testutils.NewBlockingRW()
|
|
|
- c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c := getRawConnection(NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
c.Start()
|
|
|
defer closeAndWait(c, rw)
|
|
|
|
|
@@ -889,7 +889,7 @@ func TestDispatcherToCloseDeadlock(t *testing.T) {
|
|
|
// the model callbacks (ClusterConfig).
|
|
|
m := newTestModel()
|
|
|
rw := testutils.NewBlockingRW()
|
|
|
- c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
|
|
+ c := getRawConnection(NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, nil))
|
|
|
m.ccFn = func(devID DeviceID, cc ClusterConfig) {
|
|
|
c.Close(errManual)
|
|
|
}
|
|
@@ -962,17 +962,28 @@ func TestIndexIDString(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func closeAndWait(c Connection, closers ...io.Closer) {
|
|
|
+func closeAndWait(c interface{}, closers ...io.Closer) {
|
|
|
for _, closer := range closers {
|
|
|
closer.Close()
|
|
|
}
|
|
|
var raw *rawConnection
|
|
|
switch i := c.(type) {
|
|
|
- case wireFormatConnection:
|
|
|
- raw = i.Connection.(*rawConnection)
|
|
|
case *rawConnection:
|
|
|
raw = i
|
|
|
+ default:
|
|
|
+ raw = getRawConnection(c.(Connection))
|
|
|
}
|
|
|
raw.internalClose(ErrClosed)
|
|
|
raw.loopWG.Wait()
|
|
|
}
|
|
|
+
|
|
|
+func getRawConnection(c Connection) *rawConnection {
|
|
|
+ var raw *rawConnection
|
|
|
+ switch i := c.(type) {
|
|
|
+ case wireFormatConnection:
|
|
|
+ raw = i.Connection.(encryptedConnection).conn
|
|
|
+ case encryptedConnection:
|
|
|
+ raw = i.conn
|
|
|
+ }
|
|
|
+ return raw
|
|
|
+}
|