|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
|