From a7daff358786dfde422fefe8121fa02f9f248374 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 13 Jul 2023 22:08:35 +0800 Subject: [PATCH] chore: make servicegroup panic as demand (#3422) --- core/service/servicegroup.go | 2 +- core/service/servicegroup_test.go | 48 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/service/servicegroup.go b/core/service/servicegroup.go index a71f8dd7..27ec45ad 100644 --- a/core/service/servicegroup.go +++ b/core/service/servicegroup.go @@ -68,7 +68,7 @@ func (sg *ServiceGroup) doStart() { for i := range sg.services { service := sg.services[i] - routineGroup.RunSafe(func() { + routineGroup.Run(func() { service.Start() }) } diff --git a/core/service/servicegroup_test.go b/core/service/servicegroup_test.go index e2957368..276d19c1 100644 --- a/core/service/servicegroup_test.go +++ b/core/service/servicegroup_test.go @@ -14,30 +14,6 @@ var ( done = make(chan struct{}) ) -type mockedService struct { - quit chan struct{} - multiplier int -} - -func newMockedService(multiplier int) *mockedService { - return &mockedService{ - quit: make(chan struct{}), - multiplier: multiplier, - } -} - -func (s *mockedService) Start() { - mutex.Lock() - number *= s.multiplier - mutex.Unlock() - done <- struct{}{} - <-s.quit -} - -func (s *mockedService) Stop() { - close(s.quit) -} - func TestServiceGroup(t *testing.T) { multipliers := []int{2, 3, 5, 7} want := 1 @@ -126,3 +102,27 @@ type mockedStarter struct { func (s mockedStarter) Start() { s.fn() } + +type mockedService struct { + quit chan struct{} + multiplier int +} + +func newMockedService(multiplier int) *mockedService { + return &mockedService{ + quit: make(chan struct{}), + multiplier: multiplier, + } +} + +func (s *mockedService) Start() { + mutex.Lock() + number *= s.multiplier + mutex.Unlock() + done <- struct{}{} + <-s.quit +} + +func (s *mockedService) Stop() { + close(s.quit) +}