Skip to content

Commit

Permalink
update tests to eliminate race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrSaber committed May 31, 2022
1 parent 80d6425 commit 9dd141e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dequeue_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ func TestBlockingPushFront(t *testing.T) {
}

// Remove the element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.Remove(dequeue.list.Front())
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if dequeue.list.Front().Value.(int) != 2 {
Expand Down Expand Up @@ -143,8 +145,10 @@ func TestBlockingPushBack(t *testing.T) {
}

// Remove the element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.Remove(dequeue.list.Back())
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if dequeue.list.Back().Value.(int) != 2 {
Expand Down Expand Up @@ -194,8 +198,10 @@ func TestBlockingPopFront(t *testing.T) {
}

// Add element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.PushFront(1)
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if value != 1 {
Expand Down Expand Up @@ -245,8 +251,10 @@ func TestBlockingPopBack(t *testing.T) {
}

// Add element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.PushBack(1)
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if value != 1 {
Expand Down Expand Up @@ -295,8 +303,10 @@ func TestBlockingPeekFront(t *testing.T) {
}

// Add element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.PushFront(1)
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if value != 1 {
Expand Down Expand Up @@ -353,8 +363,10 @@ func TestBlockingPeekBack(t *testing.T) {
}

// Add element to empty the dequeue and unblock the goroutine
dequeue.writeCond.L.Lock()
dequeue.list.PushBack(1)
dequeue.writeCond.Signal()
dequeue.writeCond.L.Unlock()
wg.Wait()

if value != 1 {
Expand Down

0 comments on commit 9dd141e

Please sign in to comment.