github.com/koko1123/flow-go-1@v0.29.6/fvm/runtime/reusable_cadence_runtime_test.go (about) 1 package runtime 2 3 import ( 4 "testing" 5 6 "github.com/onflow/cadence/runtime" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestReusableCadanceRuntimePoolUnbuffered(t *testing.T) { 11 pool := NewReusableCadenceRuntimePool(0, runtime.Config{}) 12 require.Nil(t, pool.pool) 13 14 entry := pool.Borrow(nil) 15 require.NotNil(t, entry) 16 17 pool.Return(entry) 18 19 entry2 := pool.Borrow(nil) 20 require.NotNil(t, entry2) 21 22 require.NotSame(t, entry, entry2) 23 } 24 25 func TestReusableCadanceRuntimePoolBuffered(t *testing.T) { 26 pool := NewReusableCadenceRuntimePool(100, runtime.Config{}) 27 require.NotNil(t, pool.pool) 28 29 select { 30 case <-pool.pool: 31 require.True(t, false) 32 default: 33 } 34 35 entry := pool.Borrow(nil) 36 require.NotNil(t, entry) 37 38 select { 39 case <-pool.pool: 40 require.True(t, false) 41 default: 42 } 43 44 pool.Return(entry) 45 46 entry2 := pool.Borrow(nil) 47 require.NotNil(t, entry2) 48 49 require.Same(t, entry, entry2) 50 } 51 52 func TestReusableCadanceRuntimePoolSharing(t *testing.T) { 53 pool := NewReusableCadenceRuntimePool(100, runtime.Config{}) 54 require.NotNil(t, pool.pool) 55 56 select { 57 case <-pool.pool: 58 require.True(t, false) 59 default: 60 } 61 62 var otherPool ReusableCadenceRuntimePool = pool 63 64 entry := otherPool.Borrow(nil) 65 require.NotNil(t, entry) 66 67 select { 68 case <-pool.pool: 69 require.True(t, false) 70 default: 71 } 72 73 otherPool.Return(entry) 74 75 entry2 := pool.Borrow(nil) 76 require.NotNil(t, entry2) 77 78 require.Same(t, entry, entry2) 79 }