Skip to content

Commit dbee85d

Browse files
authored
[#84] Added StopAll() invocation for sigterm and sigint os events. (#85)
* [#84] Added StopAll() invocation for sigterm and sigint os events. * [#84] Fixed the test case.
1 parent fcc4dd0 commit dbee85d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lifecycle/simple_component.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (sc *SimpleComponent) Start() (err error) {
6161
sc.CompState = Error
6262
} else {
6363
sc.CompState = Running
64+
6465
}
6566
if sc.OnStateChange != nil {
6667
sc.OnStateChange(Starting, sc.CompState)
@@ -274,5 +275,17 @@ func NewSimpleComponentManager() ComponentManager {
274275
cMutex: &sync.RWMutex{},
275276
waitChan: make(chan struct{}),
276277
}
278+
sigs := make(chan os.Signal, 1)
279+
280+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
281+
282+
go func(manager ComponentManager) {
283+
sig := <-sigs
284+
logger.ErrorF("Received signal: %v, Stopping all components", sig)
285+
err := manager.StopAll()
286+
if err != nil {
287+
logger.ErrorF("Error stopping components: %v", err)
288+
}
289+
}(manager)
277290
return manager
278291
}

managers/item_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestItemManager_Items_AfterUnregister(t *testing.T) {
5252
manager.Unregister("item2")
5353

5454
items := manager.Items()
55-
expectedItems := []int{1, 3}
55+
assert.ListHas(t, 1, items)
56+
assert.ListHas(t, 3, items)
5657

57-
assert.ElementsMatch(t, items, expectedItems...)
5858
}

0 commit comments

Comments
 (0)