Skip to content

Commit 598ab58

Browse files
Merge pull request #171 from ANPez/master
Release lock before .WaitUntil
2 parents cd206b0 + 8879a01 commit 598ab58

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

mock/mock_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,3 +1130,29 @@ func Test_Arguments_Bool(t *testing.T) {
11301130
assert.Equal(t, true, args.Bool(2))
11311131

11321132
}
1133+
1134+
func Test_WaitUntil_Parallel(t *testing.T) {
1135+
1136+
// make a test impl object
1137+
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
1138+
1139+
ch1 := make(chan time.Time)
1140+
ch2 := make(chan time.Time)
1141+
1142+
mockedService.Mock.On("TheExampleMethod2", true).Return().WaitUntil(ch2).Run(func(args Arguments) {
1143+
ch1 <- time.Now()
1144+
})
1145+
1146+
mockedService.Mock.On("TheExampleMethod2", false).Return().WaitUntil(ch1)
1147+
1148+
// Lock both goroutines on the .WaitUntil method
1149+
go func() {
1150+
mockedService.TheExampleMethod2(false)
1151+
}()
1152+
go func() {
1153+
mockedService.TheExampleMethod2(true)
1154+
}()
1155+
1156+
// Allow the first call to execute, so the second one executes afterwards
1157+
ch2 <- time.Now()
1158+
}

0 commit comments

Comments
 (0)