api: More semaphore tests

This commit is contained in:
Armon Dadgar 2015-01-12 18:18:32 -08:00
parent 8ad16ca390
commit 5107f5d1f9
1 changed files with 30 additions and 0 deletions

View File

@ -182,3 +182,33 @@ func TestSemaphore_Contend(t *testing.T) {
}
}
}
func TestSemaphore_BadLimit(t *testing.T) {
c, s := makeClient(t)
defer s.stop()
sema, err := c.SemaphorePrefix("test/semaphore", 0)
if err == nil {
t.Fatalf("should error")
}
sema, err = c.SemaphorePrefix("test/semaphore", 1)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = sema.Acquire(nil)
if err != nil {
t.Fatalf("err: %v", err)
}
sema2, err := c.SemaphorePrefix("test/semaphore", 2)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = sema2.Acquire(nil)
if err.Error() != "semaphore limit conflict (lock: 1, local: 2)" {
t.Fatalf("err: %v", err)
}
}