Close waits for any buckets to be cleaned, and closes the pool.
(ctx context.Context)
| 460 | |
| 461 | // Close waits for any buckets to be cleaned, and closes the pool. |
| 462 | func (tbp *TestBucketPool) Close(ctx context.Context) { |
| 463 | if tbp == nil { |
| 464 | // noop |
| 465 | return |
| 466 | } |
| 467 | defer tbp.printStats() |
| 468 | |
| 469 | if !tbp.needsBucketTeardown { |
| 470 | return |
| 471 | } |
| 472 | tbp.Logf(ctx, "Closing TestBucketPool and closing all buckets") |
| 473 | // Cancel async workers |
| 474 | if tbp.ctxCancelFunc != nil { |
| 475 | tbp.ctxCancelFunc() |
| 476 | tbp.Logf(ctx, "Waiting for bucket readier to finish") |
| 477 | tbp.bucketReadierWaitGroup.Wait() |
| 478 | tbp.Logf(ctx, "Waiting for bucket creation to finish") |
| 479 | <-tbp.bucketCreationDoneChan |
| 480 | tbp.Logf(ctx, "Bucket creation finished") |
| 481 | } |
| 482 | |
| 483 | if tbp.cluster != nil { |
| 484 | bucketLoop: |
| 485 | for _ = range tbp.numBuckets { |
| 486 | select { |
| 487 | case bucket := <-tbp.readyBucketPool: |
| 488 | tbp.Logf(ctx, "Closing bucket %s", bucket.GetName()) |
| 489 | bucket.Close(ctx) |
| 490 | default: |
| 491 | break bucketLoop |
| 492 | } |
| 493 | } |
| 494 | if err := tbp.cluster.close(); err != nil { |
| 495 | tbp.Logf(ctx, "Couldn't close cluster connection: %v", err) |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // removeOldTestBuckets removes all buckets starting with testBucketNamePrefix |
| 501 | func (tbp *TestBucketPool) removeOldTestBuckets(ctx context.Context) error { |