code.vegaprotocol.io/vega@v0.79.0/core/coreapi/services/netparams_test.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package services_test 17 18 import ( 19 "context" 20 "sync" 21 "testing" 22 "time" 23 24 "code.vegaprotocol.io/vega/core/coreapi/services" 25 "code.vegaprotocol.io/vega/core/events" 26 27 "github.com/stretchr/testify/assert" 28 "github.com/stretchr/testify/require" 29 ) 30 31 func TestNetParams(t *testing.T) { 32 ctx, cancel := context.WithCancel(context.Background()) 33 34 np := services.NewNetParams(ctx) 35 wg := sync.WaitGroup{} 36 wg.Add(1) 37 allSent := false 38 39 maxEvents := 1000000 40 41 evts := make([]events.Event, maxEvents) 42 43 for i := 0; i < maxEvents; i++ { 44 evts[i] = events.NewNetworkParameterEvent(ctx, "foo", "bar") 45 } 46 47 require.NotPanics(t, func() { 48 go func() { 49 np.Push( 50 evts..., 51 ) 52 allSent = true 53 wg.Done() 54 }() 55 }) 56 57 // slight pause to give the goroutine a chance to start pushing before we cancel the context 58 time.Sleep(time.Millisecond) 59 cancel() 60 61 wg.Wait() 62 63 assert.True(t, allSent) 64 }