Skip to content

Commit

Permalink
Merge pull request #329 from scylladb/dk/328-testsimpledebouncercase_…
Browse files Browse the repository at this point in the history
…2-cas-stuck-forever

fix(simple_debouncer_test): make sure first call is picked up before making more calls
  • Loading branch information
sylwiaszunejko authored Nov 10, 2024
2 parents 23e808b + d1f2dd1 commit c594ff2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions debounce/simple_debouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ func TestSimpleDebouncer(t *testing.T) {
t.Errorf("Expected function to be executed only once, but got %d executions", executions)
}
})

atomic.StoreInt32(&executions, 0)
t.Run("Case 2", func(t *testing.T) {
// Case 2: Debounce the function multiple times at row when body is started
go d.Debounce(fn)
startedCh <- struct{}{}
// Wait until first call execution started
waitTillChannelIsEmpty(startedCh)
// Call function twice, due to debounce only one should be executed
go d.Debounce(fn)
go d.Debounce(fn)
// Let first call to complete
doneCh <- struct{}{}
// Let second call to complete
startedCh <- struct{}{}
doneCh <- struct{}{}
// Make sure second call is completed
waitTillChannelIsEmpty(doneCh)
// We expect that the function has only executed once due to debouncing
if atomic.LoadInt32(&executions) != 2 {
Expand Down

0 comments on commit c594ff2

Please sign in to comment.