Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: worker UT race condition (in UT, not in worker) #4106

Open
jlearman opened this issue Jul 9, 2024 · 1 comment
Open

Bug: worker UT race condition (in UT, not in worker) #4106

jlearman opened this issue Jul 9, 2024 · 1 comment
Labels

Comments

@jlearman
Copy link

jlearman commented Jul 9, 2024

Describe the bug.

The use of testEnded in worker/worker_test.go causes race condition test failures.

Describe the steps to reproduce the behavior.

cd worker
go test -race

results in race condition test failures

Expected behavior.

no race condition test failures

Screenshots.

No response

Operating Environment

any development workstation

Additional Information

The fix is simple: change monitorTest() to accept a channel instead of a boolean pointer, and have it detect test-done using the following in the loop:

        if _, ok := <-ch; !ok {
            break
        }

Calling code creates & passes the channel, and closes the channel to signal test-done.

@jlearman jlearman added the bug label Jul 9, 2024
@jlearman jlearman changed the title Bug: Bug: worker UT race condition (in UT, not in worker) Jul 9, 2024
@jlearman
Copy link
Author

jlearman commented Jul 9, 2024

There's also a race accessing TestWorker.CommandCount, which can easily be fixed using these instead of direct accesses, in any concurrently executed code:

func (t *TestWorker) GetCommandCount() int {
    t.mutex.Lock()
    defer t.mutex.Unlock()
    return t.CommandCount
}

func (t *TestWorker) IncrementCommandCount() {
    t.mutex.Lock()
    defer t.mutex.Unlock()
    t.CommandCount++
    fmt.Println("HERE", t.CommandCount, t)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant