Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Sep 4, 2024
1 parent 4697ecb commit 6c44d61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1,035 deletions.
36 changes: 36 additions & 0 deletions internal/pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,5 +842,41 @@ func TestPool(t *testing.T) {
wg.Wait()
})
})
t.Run("PutInFull", func(t *testing.T) {
p := New(rootCtx,
WithLimit[*testItem, testItem](1),
WithCreateItemTimeout[*testItem, testItem](50*time.Millisecond),
WithCloseItemTimeout[*testItem, testItem](50*time.Millisecond),
// replace default async closer for sync testing
withCloseItemFunc(func(ctx context.Context, item *testItem) {
_ = item.Close(ctx)
}),
)
item := mustGetItem(t, p)
if err := p.putItem(context.Background(), item); err != nil {
t.Fatalf("unexpected error on put session into non-full client: %v, wand: %v", err, nil)
}

if err := p.putItem(context.Background(), &testItem{}); !xerrors.Is(err, errPoolIsOverflow) {
t.Fatalf("unexpected error on put item into full pool: %v, wand: %v", err, errPoolIsOverflow)
}
})
t.Run("PutTwice", func(t *testing.T) {
p := New(rootCtx,
WithLimit[*testItem, testItem](2),
WithCreateItemTimeout[*testItem, testItem](50*time.Millisecond),
WithCloseItemTimeout[*testItem, testItem](50*time.Millisecond),
// replace default async closer for sync testing
withCloseItemFunc(func(ctx context.Context, item *testItem) {
_ = item.Close(ctx)
}),
)
item := mustGetItem(t, p)
mustPutItem(t, p, item)

require.Panics(t, func() {
_ = p.putItem(context.Background(), item)
})
})
})
}
Loading

0 comments on commit 6c44d61

Please sign in to comment.