mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-05-01 09:03:12 +00:00
test Start/Stop race
This commit is contained in:
parent
d64a04f0d1
commit
b0588c14a9
@ -82,14 +82,19 @@ func (wf *WakuFilterLightNode) SetHost(h host.Host) {
|
||||
}
|
||||
|
||||
func (wf *WakuFilterLightNode) Start(ctx context.Context) error {
|
||||
wf.log.Info("starting again")
|
||||
if !wf.started.CompareAndSwap(false, true) {
|
||||
return nil // Already started
|
||||
}
|
||||
wf.log.Info("starting")
|
||||
|
||||
wf.wg.Wait() // Wait for any goroutines to stop
|
||||
wf.log.Info("setting cancel")
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
wf.log.Info("built cancel")
|
||||
wf.cancel = cancel
|
||||
wf.log.Info("made cancel")
|
||||
wf.ctx = ctx
|
||||
wf.subscriptions = NewSubscriptionMap(wf.log)
|
||||
|
||||
@ -105,6 +110,7 @@ func (wf *WakuFilterLightNode) Stop() {
|
||||
if !wf.started.CompareAndSwap(true, false) {
|
||||
return
|
||||
}
|
||||
wf.log.Info("stopping node")
|
||||
|
||||
wf.cancel()
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ func (s *FilterTestSuite) makeWakuRelay(topic string) (*relay.WakuRelay, *relay.
|
||||
return relay, sub, host, broadcaster
|
||||
}
|
||||
|
||||
func (s *FilterTestSuite) makeWakuFilterLightNode() *WakuFilterLightNode {
|
||||
func (s *FilterTestSuite) makeWakuFilterLightNode(start bool) *WakuFilterLightNode {
|
||||
port, err := tests.FindFreePort(s.T(), "", 5)
|
||||
s.Require().NoError(err)
|
||||
|
||||
@ -79,8 +79,10 @@ func (s *FilterTestSuite) makeWakuFilterLightNode() *WakuFilterLightNode {
|
||||
filterPush := NewWakuFilterLightNode(b, nil, timesource.NewDefaultClock(), prometheus.DefaultRegisterer, s.log)
|
||||
filterPush.SetHost(host)
|
||||
s.lightNodeHost = host
|
||||
err = filterPush.Start(context.Background())
|
||||
s.Require().NoError(err)
|
||||
if start {
|
||||
err = filterPush.Start(context.Background())
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
return filterPush
|
||||
}
|
||||
@ -178,7 +180,7 @@ func (s *FilterTestSuite) SetupTest() {
|
||||
s.testTopic = "/waku/2/go/filter/test"
|
||||
s.testContentTopic = "TopicA"
|
||||
|
||||
s.lightNode = s.makeWakuFilterLightNode()
|
||||
s.lightNode = s.makeWakuFilterLightNode(true)
|
||||
|
||||
s.relayNode, s.fullNode = s.makeWakuFilterFullNode(s.testTopic)
|
||||
|
||||
@ -354,6 +356,34 @@ func (s *FilterTestSuite) TestRunningGuard() {
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *FilterTestSuite) TestStartStop() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
s.lightNode = s.makeWakuFilterLightNode(false)
|
||||
|
||||
stopNode := func() {
|
||||
for i := 0; i < 100000; i++ {
|
||||
s.lightNode.Stop()
|
||||
//s.contentFilter.Topic = "something"
|
||||
//s.contentFilter.ContentTopics = []string{"something"}
|
||||
// s.lightNode.Unsubscribe(s.ctx, s.contentFilter, Peer(s.fullNodeHost.ID()))
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
startNode := func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
s.lightNode.Start(context.Background())
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
go startNode()
|
||||
go stopNode()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (s *FilterTestSuite) TestFireAndForgetAndCustomWg() {
|
||||
contentFilter := ContentFilter{
|
||||
Topic: "test",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user