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

Release lock before .WaitUntil #171

Merged
merged 4 commits into from
Dec 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,3 +987,29 @@ func Test_Arguments_Bool(t *testing.T) {
assert.Equal(t, true, args.Bool(2))

}

func Test_WaitUntil_Parallel(t *testing.T) {

// make a test impl object
var mockedService *TestExampleImplementation = new(TestExampleImplementation)

ch1 := make(chan time.Time)
ch2 := make(chan time.Time)

mockedService.Mock.On("TheExampleMethod2", true).Return().WaitUntil(ch2).Run(func(args Arguments) {
ch1 <- time.Now()
})

mockedService.Mock.On("TheExampleMethod2", false).Return().WaitUntil(ch1)

// Lock both goroutines on the .WaitUntil method
go func() {
mockedService.TheExampleMethod2(false)
}()
go func() {
mockedService.TheExampleMethod2(true)
}()

// Allow the first call to execute, so the second one executes afterwards
ch2 <- time.Now()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to have each go func() write something and assert the order is correct at the end of the test?

}