Skip to content

Commit

Permalink
Fix appending to queue after was cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun authored Oct 18, 2020
2 parents a40b88f + 696cf80 commit 3605a37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (q *Queue) Clean() {
q.items = make(map[int64]interface{})
q.ids = make(map[interface{}]int64)
q.buf = make([]int64, minQueueLen)
q.tail = 0
q.head = 0
q.count = 0
}

// Returns the number of elements in queue
Expand Down
14 changes: 14 additions & 0 deletions queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,20 @@ func TestTestQueueClean(t *testing.T) {
}
}

func TestTestQueueClean2(t *testing.T) {
q := New()

for i := 0; i < 50; i++ {
q.Append(i)
}

q.Clean()

for i := 0; i < 50; i++ {
q.Append(i)
}
}

// General warning: Go's benchmark utility (go test -bench .) increases the number of
// iterations until the benchmarks take a reasonable amount of time to run; memory usage
// is *NOT* considered. On my machine, these benchmarks hit around ~1GB before they've had
Expand Down

0 comments on commit 3605a37

Please sign in to comment.