@@ -51,59 +51,102 @@ func (u *mockUpgradeManager) Ack(ctx context.Context, acker acker.Acker) error {
51
51
}
52
52
53
53
func TestUpgradeHandler (t * testing.T ) {
54
+ // Create a cancellable context that will shut down the coordinator after
55
+ // the test.
56
+ ctx , cancel := context .WithCancel (context .Background ())
57
+ defer cancel ()
58
+
54
59
log , _ := logger .New ("" , false )
55
- ack := noopacker .New ()
56
60
agentInfo , _ := info .NewAgentInfo (true )
57
61
msgChan := make (chan string )
58
- upgradeMgr := & mockUpgradeManager {msgChan : msgChan }
59
- specs := component.RuntimeSpecs {}
60
- c := coordinator .New (log , configuration .DefaultConfiguration (), logger .DefaultLogLevel , agentInfo , specs , nil , upgradeMgr , nil , nil , nil , nil , nil , false )
62
+
63
+ // Create and start the coordinator
64
+ c := coordinator .New (
65
+ log ,
66
+ configuration .DefaultConfiguration (),
67
+ logger .DefaultLogLevel ,
68
+ agentInfo ,
69
+ component.RuntimeSpecs {},
70
+ nil ,
71
+ & mockUpgradeManager {msgChan : msgChan },
72
+ nil , nil , nil , nil , nil , false )
73
+ //nolint:errcheck // We don't need the termination state of the Coordinator
74
+ go c .Run (ctx )
75
+
61
76
u := NewUpgrade (log , c )
62
- ctx := context .Background ()
63
77
a := fleetapi.ActionUpgrade {Version : "8.3.0" , SourceURI : "http://localhost" }
78
+ ack := noopacker .New ()
64
79
err := u .Handle (ctx , & a , ack )
65
80
require .NoError (t , err )
66
81
msg := <- msgChan
67
82
require .Equal (t , "completed 8.3.0" , msg )
68
83
}
69
84
70
85
func TestUpgradeHandlerSameVersion (t * testing.T ) {
86
+ // Create a cancellable context that will shut down the coordinator after
87
+ // the test.
88
+ ctx , cancel := context .WithCancel (context .Background ())
89
+ defer cancel ()
90
+
71
91
log , _ := logger .New ("" , false )
72
- ack := noopacker .New ()
73
92
agentInfo , _ := info .NewAgentInfo (true )
74
93
msgChan := make (chan string )
75
- upgradeMgr := & mockUpgradeManager {msgChan : msgChan }
76
- specs := component.RuntimeSpecs {}
77
- c := coordinator .New (log , configuration .DefaultConfiguration (), logger .DefaultLogLevel , agentInfo , specs , nil , upgradeMgr , nil , nil , nil , nil , nil , false )
94
+
95
+ // Create and start the Coordinator
96
+ c := coordinator .New (
97
+ log ,
98
+ configuration .DefaultConfiguration (),
99
+ logger .DefaultLogLevel ,
100
+ agentInfo ,
101
+ component.RuntimeSpecs {},
102
+ nil ,
103
+ & mockUpgradeManager {msgChan : msgChan },
104
+ nil , nil , nil , nil , nil , false )
105
+ //nolint:errcheck // We don't need the termination state of the Coordinator
106
+ go c .Run (ctx )
107
+
78
108
u := NewUpgrade (log , c )
79
- ctx1 := context .Background ()
80
- ctx2 := context .Background ()
81
109
a := fleetapi.ActionUpgrade {Version : "8.3.0" , SourceURI : "http://localhost" }
82
- err1 := u .Handle (ctx1 , & a , ack )
83
- err2 := u .Handle (ctx2 , & a , ack )
110
+ ack := noopacker .New ()
111
+ err1 := u .Handle (ctx , & a , ack )
112
+ err2 := u .Handle (ctx , & a , ack )
84
113
require .NoError (t , err1 )
85
114
require .NoError (t , err2 )
86
115
msg := <- msgChan
87
116
require .Equal (t , "completed 8.3.0" , msg )
88
117
}
89
118
90
119
func TestUpgradeHandlerNewVersion (t * testing.T ) {
120
+ // Create a cancellable context that will shut down the coordinator after
121
+ // the test.
122
+ ctx , cancel := context .WithCancel (context .Background ())
123
+ defer cancel ()
124
+
91
125
log , _ := logger .New ("" , false )
92
- ack := noopacker .New ()
93
126
agentInfo , _ := info .NewAgentInfo (true )
94
127
msgChan := make (chan string )
95
- upgradeMgr := & mockUpgradeManager {msgChan : msgChan }
96
- specs := component.RuntimeSpecs {}
97
- c := coordinator .New (log , configuration .DefaultConfiguration (), logger .DefaultLogLevel , agentInfo , specs , nil , upgradeMgr , nil , nil , nil , nil , nil , false )
128
+
129
+ // Create and start the Coordinator
130
+ c := coordinator .New (
131
+ log ,
132
+ configuration .DefaultConfiguration (),
133
+ logger .DefaultLogLevel ,
134
+ agentInfo ,
135
+ component.RuntimeSpecs {},
136
+ nil ,
137
+ & mockUpgradeManager {msgChan : msgChan },
138
+ nil , nil , nil , nil , nil , false )
139
+ //nolint:errcheck // We don't need the termination state of the Coordinator
140
+ go c .Run (ctx )
141
+
98
142
u := NewUpgrade (log , c )
99
- ctx1 := context .Background ()
100
- ctx2 := context .Background ()
101
143
a1 := fleetapi.ActionUpgrade {Version : "8.2.0" , SourceURI : "http://localhost" }
102
144
a2 := fleetapi.ActionUpgrade {Version : "8.5.0" , SourceURI : "http://localhost" }
103
- err1 := u .Handle (ctx1 , & a1 , ack )
145
+ ack := noopacker .New ()
146
+ err1 := u .Handle (ctx , & a1 , ack )
104
147
require .NoError (t , err1 )
105
148
time .Sleep (1 * time .Second )
106
- err2 := u .Handle (ctx2 , & a2 , ack )
149
+ err2 := u .Handle (ctx , & a2 , ack )
107
150
require .NoError (t , err2 )
108
151
msg1 := <- msgChan
109
152
require .Equal (t , "canceled 8.2.0" , msg1 )
0 commit comments