apiserver: rename test variables

This commit is contained in:
Abu Kashem 2021-07-14 10:29:53 -04:00
parent 48da959dbf
commit e838173306
No known key found for this signature in database
GPG Key ID: 33A4FA7088DB68A9

View File

@ -53,12 +53,12 @@ type result struct {
} }
// wrap a lifecycleSignal so the test can inject its own callback // wrap a lifecycleSignal so the test can inject its own callback
type wrappedTerminationSignal struct { type wrappedLifecycleSignal struct {
lifecycleSignal lifecycleSignal
callback func(bool, string, lifecycleSignal) callback func(bool, string, lifecycleSignal)
} }
func (w *wrappedTerminationSignal) Signal() { func (w *wrappedLifecycleSignal) Signal() {
var name string var name string
if ncw, ok := w.lifecycleSignal.(*namedChannelWrapper); ok { if ncw, ok := w.lifecycleSignal.(*namedChannelWrapper); ok {
name = ncw.name name = ncw.name
@ -74,18 +74,18 @@ func (w *wrappedTerminationSignal) Signal() {
} }
} }
func wrapTerminationSignals(t *testing.T, ts *lifecycleSignals, callback func(bool, string, lifecycleSignal)) { func wrapLifecycleSignals(t *testing.T, ts *lifecycleSignals, callback func(bool, string, lifecycleSignal)) {
newWrappedTerminationSignal := func(delegated lifecycleSignal) lifecycleSignal { newWrappedLifecycleSignal := func(delegated lifecycleSignal) lifecycleSignal {
return &wrappedTerminationSignal{ return &wrappedLifecycleSignal{
lifecycleSignal: delegated, lifecycleSignal: delegated,
callback: callback, callback: callback,
} }
} }
ts.AfterShutdownDelayDuration = newWrappedTerminationSignal(ts.AfterShutdownDelayDuration) ts.AfterShutdownDelayDuration = newWrappedLifecycleSignal(ts.AfterShutdownDelayDuration)
ts.HTTPServerStoppedListening = newWrappedTerminationSignal(ts.HTTPServerStoppedListening) ts.HTTPServerStoppedListening = newWrappedLifecycleSignal(ts.HTTPServerStoppedListening)
ts.InFlightRequestsDrained = newWrappedTerminationSignal(ts.InFlightRequestsDrained) ts.InFlightRequestsDrained = newWrappedLifecycleSignal(ts.InFlightRequestsDrained)
ts.ShutdownInitiated = newWrappedTerminationSignal(ts.ShutdownInitiated) ts.ShutdownInitiated = newWrappedLifecycleSignal(ts.ShutdownInitiated)
} }
type step struct { type step struct {
@ -157,7 +157,7 @@ func TestGracefulTerminationWithKeepListeningDuringGracefulTerminationDisabled(t
} }
// wrap the termination signals of the GenericAPIServer so the test can inject its own callback // wrap the termination signals of the GenericAPIServer so the test can inject its own callback
wrapTerminationSignals(t, &s.lifecycleSignals, func(before bool, name string, e lifecycleSignal) { wrapLifecycleSignals(t, &s.lifecycleSignals, func(before bool, name string, e lifecycleSignal) {
recordOrderFn(before, name, e) recordOrderFn(before, name, e)
steps(before, name, e) steps(before, name, e)
}) })
@ -217,7 +217,7 @@ func TestGracefulTerminationWithKeepListeningDuringGracefulTerminationDisabled(t
t.Fatal("Expected the apiserver Run method to return") t.Fatal("Expected the apiserver Run method to return")
} }
terminationSignalOrderExpected := []string{ lifecycleSignalOrderExpected := []string{
string("ShutdownInitiated"), string("ShutdownInitiated"),
string("AfterShutdownDelayDuration"), string("AfterShutdownDelayDuration"),
string("HTTPServerStoppedListening"), string("HTTPServerStoppedListening"),
@ -226,8 +226,8 @@ func TestGracefulTerminationWithKeepListeningDuringGracefulTerminationDisabled(t
func() { func() {
signalOrderLock.Lock() signalOrderLock.Lock()
defer signalOrderLock.Unlock() defer signalOrderLock.Unlock()
if !reflect.DeepEqual(terminationSignalOrderExpected, signalOrderGot) { if !reflect.DeepEqual(lifecycleSignalOrderExpected, signalOrderGot) {
t.Errorf("Expected order of termination event signal to match, diff: %s", cmp.Diff(terminationSignalOrderExpected, signalOrderGot)) t.Errorf("Expected order of termination event signal to match, diff: %s", cmp.Diff(lifecycleSignalOrderExpected, signalOrderGot))
} }
}() }()
} }