Skip to content

Commit

Permalink
Add more tests. Add go 1.16 to travis cfg.
Browse files Browse the repository at this point in the history
  • Loading branch information
marusama committed Mar 28, 2021
1 parent 41c532b commit 2d3c1ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ language: go
go:
- 1.13.x
- 1.14.x
- 1.15.x
- 1.16.x
- 1.x
- master

Expand Down
20 changes: 20 additions & 0 deletions semaphore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ func TestSemaphore_SetLimit_decrease_limit(t *testing.T) {
checkLimitAndCount(t, sem, 1, 0)
}

func TestSemaphore_New0_SetLimit1_Acquire_Release_SetLimit0(t *testing.T) {
sem := New(0)
checkLimitAndCount(t, sem, 0, 0)

sem.SetLimit(1)
checkLimitAndCount(t, sem, 1, 0)

sem.Acquire(nil, 1)
checkLimitAndCount(t, sem, 1, 1)

oldCnt := sem.Release(1)
if oldCnt != 1 {
t.Error("semaphore must have old count = ", 1, ", but has ", oldCnt)
}
checkLimitAndCount(t, sem, 1, 0)

sem.SetLimit(0)
checkLimitAndCount(t, sem, 0, 0)
}

func TestSemaphore_SetLimit_increase_broadcast(t *testing.T) {
getWGs := func(cnt int) []*sync.WaitGroup {
wgs := make([]*sync.WaitGroup, cnt)
Expand Down

0 comments on commit 2d3c1ea

Please sign in to comment.