Commit cb9cccf 1 parent 696ed9a commit cb9cccf Copy full SHA for cb9cccf
File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -46,8 +46,9 @@ func (sig ShutdownSignal) String() string {
46
46
47
47
func newSignalReceivers () signalReceivers {
48
48
return signalReceivers {
49
- notify : signal .Notify ,
50
- signals : make (chan os.Signal , 1 ),
49
+ notify : signal .Notify ,
50
+ stopNotify : signal .Stop ,
51
+ signals : make (chan os.Signal , 1 ),
51
52
}
52
53
}
53
54
@@ -64,7 +65,8 @@ type signalReceivers struct {
64
65
finished chan struct {}
65
66
66
67
// this stub allows us to unit test signal relay functionality
67
- notify func (c chan <- os.Signal , sig ... os.Signal )
68
+ notify func (c chan <- os.Signal , sig ... os.Signal )
69
+ stopNotify func (c chan <- os.Signal )
68
70
69
71
// last will contain a pointer to the last ShutdownSignal received, or
70
72
// nil if none, if a new channel is created by Wait or Done, this last
@@ -118,6 +120,7 @@ func (recv *signalReceivers) Start(ctx context.Context) {
118
120
func (recv * signalReceivers ) Stop (ctx context.Context ) error {
119
121
recv .m .Lock ()
120
122
defer recv .m .Unlock ()
123
+ recv .stopNotify (recv .signals )
121
124
122
125
// if the relayer is not running; return nil error
123
126
if ! recv .running () {
Original file line number Diff line number Diff line change @@ -100,6 +100,10 @@ func TestSignal(t *testing.T) {
100
100
}
101
101
}()
102
102
}
103
+ var stopCalledTimes int
104
+ recv .stopNotify = func (ch chan <- os.Signal ) {
105
+ stopCalledTimes ++
106
+ }
103
107
ctx , cancel := context .WithCancel (context .Background ())
104
108
defer cancel ()
105
109
recv .Start (ctx )
@@ -110,6 +114,7 @@ func TestSignal(t *testing.T) {
110
114
sig := <- recv .Wait ()
111
115
require .Equal (t , syscall .SIGTERM , sig .Signal )
112
116
require .NoError (t , recv .Stop (ctx ))
117
+ require .Equal (t , 1 , stopCalledTimes )
113
118
close (stub )
114
119
})
115
120
})
You can’t perform that action at this time.
0 commit comments