Test empty semaphore, add capacity, token can be acquired
(t *testing.T)
| 267 | |
| 268 | // Test empty semaphore, add capacity, token can be acquired |
| 269 | func TestSemaphoreAcquireHasCapacity(t *testing.T) { |
| 270 | gotChan := make(chan struct{}, 1) |
| 271 | want := 1 |
| 272 | |
| 273 | sem := newSemaphore(1, 0) |
| 274 | tryAcquire(sem, gotChan) |
| 275 | sem.updateCapacity(1) // Allows 1 acquire |
| 276 | |
| 277 | for i := 0; i < want; i++ { |
| 278 | select { |
| 279 | case <-gotChan: |
| 280 | // Successfully acquired a token. |
| 281 | case <-time.After(semAcquireTimeout): |
| 282 | t.Error("Was not able to acquire token before timeout") |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | select { |
| 287 | case <-gotChan: |
| 288 | t.Errorf("Got more acquires than wanted, want = %d, got at least %d", want, want+1) |
| 289 | case <-time.After(semNoChangeTimeout): |
| 290 | // No change happened, success. |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | func TestSemaphoreRelease(t *testing.T) { |
| 295 | sem := newSemaphore(1, 1) |
nothing calls this directly
no test coverage detected