From fb23c1750a4346294288496eec4141ad8c7b7943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 1 Apr 2019 16:48:49 +0100 Subject: [PATCH] fix data races in table-driven parallel subtests t.Parallel effectively fires off a goroutine, so we can't use the test range variable directly. That can result in different subtests using the same test case data, causing sporadic failures, or some test cases rarely being actually tested. This was uncovered while stress-testing the test suite for an unrelated refactor. While at it, one test case in TestMouseClickNode was incorrect. contextmenu fires on a right click, so ModifierNone won't fire it. This wasn't caught before, as this test case was almost never ran. After the data race fix, the test case failed consistently, before being fixed. --- input_test.go | 6 +++++- query_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/input_test.go b/input_test.go index dc6ca7b..b9bbf3a 100644 --- a/input_test.go +++ b/input_test.go @@ -79,13 +79,14 @@ func TestMouseClickNode(t *testing.T) { {"button2", "foo", ButtonType(input.ButtonNone), ByID}, {"button2", "bar", ButtonType(input.ButtonLeft), ByID}, {"button2", "bar-middle", ButtonType(input.ButtonMiddle), ByID}, + {"input3", "foo", ButtonModifiers(input.ModifierNone), ByID}, {"input3", "bar-right", ButtonType(input.ButtonRight), ByID}, - {"input3", "bar-right", ButtonModifiers(input.ModifierNone), ByID}, {"input3", "bar-right", Button("right"), ByID}, } for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "input.html") @@ -130,6 +131,7 @@ func TestMouseClickOffscreenNode(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "input.html") @@ -188,6 +190,7 @@ func TestKeyAction(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "input.html") @@ -237,6 +240,7 @@ func TestKeyActionNode(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "input.html") diff --git a/query_test.go b/query_test.go index bad525c..b379d57 100644 --- a/query_test.go +++ b/query_test.go @@ -210,6 +210,7 @@ func TestClear(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -254,6 +255,7 @@ func TestReset(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -322,6 +324,7 @@ func TestSetValue(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -496,6 +499,7 @@ func TestSetAttributes(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "image.html") @@ -570,6 +574,7 @@ func TestSetAttributeValue(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -613,6 +618,7 @@ func TestRemoveAttribute(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "image.html") @@ -651,6 +657,7 @@ func TestClick(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -691,6 +698,7 @@ func TestDoubleClick(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "js.html") @@ -732,6 +740,7 @@ func TestSendKeys(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "visible.html") @@ -816,6 +825,7 @@ func TestSubmit(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "form.html") @@ -856,6 +866,7 @@ func TestComputedStyle(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "js.html") @@ -908,6 +919,7 @@ func TestMatchedStyle(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { + test := test t.Parallel() ctx, cancel := testAllocate(t, "js.html")