tests: Fix flake in TestHostNameCollision
authorAndrey Petrov <andrey.petrov@shazow.net>
Wed, 24 Aug 2016 17:53:59 +0000 (13:53 -0400)
committerAndrey Petrov <andrey.petrov@shazow.net>
Wed, 24 Aug 2016 17:54:08 +0000 (13:54 -0400)
host_test.go

index 31caf95a559fa48fff337d06617d8e549c3ed743..e3402676eee71b4d62fa2676757248971299d14f 100644 (file)
@@ -68,13 +68,7 @@ func TestHostNameCollision(t *testing.T) {
 
                        // Consume the initial buffer
                        scanner.Scan()
-                       actual := scanner.Text()
-                       if !strings.HasPrefix(actual, "[foo] ") {
-                               // FIXME: This is flaky. :/
-                               t.Errorf("First client failed to get 'foo' name: %q", actual)
-                       }
-
-                       actual = stripPrompt(actual)
+                       actual := stripPrompt(scanner.Text())
                        expected := " * foo joined. (Connected: 1)"
                        if actual != expected {
                                t.Errorf("Got %q; expected %q", actual, expected)
@@ -84,7 +78,13 @@ func TestHostNameCollision(t *testing.T) {
                        done <- struct{}{}
 
                        scanner.Scan()
-                       actual = stripPrompt(scanner.Text())
+                       actual = scanner.Text()
+                       // This check has to happen second because prompt doesn't always
+                       // get set before the first message.
+                       if !strings.HasPrefix(actual, "[foo] ") {
+                               t.Errorf("First client failed to get 'foo' name: %q", actual)
+                       }
+                       actual = stripPrompt(actual)
                        expected = " * Guest1 joined. (Connected: 2)"
                        if actual != expected {
                                t.Errorf("Got %q; expected %q", actual, expected)