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.
This commit is contained in:
Daniel Martí 2019-04-01 16:48:49 +01:00
parent d73caffcd0
commit fb23c1750a
2 changed files with 17 additions and 1 deletions

View File

@ -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")

View File

@ -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")