github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/hnsw/visited/pool_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package visited 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestPool(t *testing.T) { 21 // pool with two liss 22 pool := NewPool(2, 2) 23 assert.Equal(t, 2, len(pool.listSets)) 24 25 // get first list 26 l1 := pool.Borrow() 27 assert.Equal(t, 2, l1.Len()) 28 assert.Equal(t, 1, len(pool.listSets)) 29 30 // get second list 31 l2 := pool.Borrow() 32 assert.Equal(t, 0, len(pool.listSets)) 33 34 // get third list from empty pool and return it back 35 l3 := pool.Borrow() 36 assert.Equal(t, 0, len(pool.listSets)) 37 pool.Return(l3) 38 assert.Equal(t, 1, len(pool.listSets)) 39 40 // get same list again and modify its size 41 // so that it is not accepted when returned to the pool 42 l3 = pool.Borrow() 43 l3.Visit(2) 44 pool.Return(l3) 45 assert.Equal(t, 0, len(pool.listSets)) 46 47 // add two list and destroy the pool 48 pool.Return(l1) 49 pool.Return(l2) 50 assert.Equal(t, 2, len(pool.listSets)) 51 pool.Destroy() 52 assert.Equal(t, 0, len(pool.listSets)) 53 }