Browse Source

lib/model: Unflake folder restart with blocking conn test (ref #5707) (#5744)

Simon Frei 6 years ago
parent
commit
129df0613b
1 changed files with 10 additions and 4 deletions
  1. 10 4
      lib/model/model_test.go

+ 10 - 4
lib/model/model_test.go

@@ -3273,6 +3273,12 @@ func TestConnCloseOnRestart(t *testing.T) {
 	br := &testutils.BlockingRW{}
 	nw := &testutils.NoopRW{}
 	m.AddConnection(newFakeProtoConn(protocol.NewConnection(device1, br, nw, m, "testConn", protocol.CompressNever)), protocol.HelloResult{})
+	m.pmut.RLock()
+	if len(m.closed) != 1 {
+		t.Fatalf("Expected just one conn (len(m.conn) == %v)", len(m.conn))
+	}
+	closed := m.closed[device1]
+	m.pmut.RUnlock()
 
 	newFcfg := fcfg.Copy()
 	newFcfg.Paused = true
@@ -3286,9 +3292,9 @@ func TestConnCloseOnRestart(t *testing.T) {
 	case <-time.After(5 * time.Second):
 		t.Fatal("Timed out before folder restart returned")
 	}
-	m.pmut.RLock()
-	defer m.pmut.RUnlock()
-	if len(m.conn) != 0 {
-		t.Errorf("Conn wasn't removed on restart (len(m.conn) == %v)", len(m.conn))
+	select {
+	case <-closed:
+	case <-time.After(5 * time.Second):
+		t.Fatal("Timed out before connection was closed")
 	}
 }