This test ensures that when a slave shuts itself down, it unregisters itself and the master notifies the framework immediately and rescinds any offers.
| 204 | // unregisters itself and the master notifies the framework |
| 205 | // immediately and rescinds any offers. |
| 206 | TEST_F(SlaveTest, Shutdown) |
| 207 | { |
| 208 | Try<Owned<cluster::Master>> master = StartMaster(); |
| 209 | ASSERT_SOME(master); |
| 210 | |
| 211 | Owned<MasterDetector> detector = master.get()->createDetector(); |
| 212 | Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); |
| 213 | ASSERT_SOME(slave); |
| 214 | |
| 215 | MockScheduler sched; |
| 216 | MesosSchedulerDriver driver( |
| 217 | &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); |
| 218 | |
| 219 | EXPECT_CALL(sched, registered(&driver, _, _)); |
| 220 | |
| 221 | Future<vector<Offer>> offers; |
| 222 | EXPECT_CALL(sched, resourceOffers(&driver, _)) |
| 223 | .WillOnce(FutureArg<1>(&offers)) |
| 224 | .WillRepeatedly(Return()); // Ignore subsequent offers. |
| 225 | |
| 226 | driver.start(); |
| 227 | |
| 228 | AWAIT_READY(offers); |
| 229 | EXPECT_EQ(1u, offers->size()); |
| 230 | |
| 231 | Future<Nothing> offerRescinded; |
| 232 | EXPECT_CALL(sched, offerRescinded(&driver, offers.get()[0].id())) |
| 233 | .WillOnce(FutureSatisfy(&offerRescinded)); |
| 234 | |
| 235 | Future<Nothing> slaveLost; |
| 236 | EXPECT_CALL(sched, slaveLost(&driver, offers.get()[0].slave_id())) |
| 237 | .WillOnce(FutureSatisfy(&slaveLost)); |
| 238 | |
| 239 | // Stop the slave with explicit shutdown message so that the slave |
| 240 | // unregisters. |
| 241 | slave.get()->shutdown(); |
| 242 | slave->reset(); |
| 243 | |
| 244 | AWAIT_READY(offerRescinded); |
| 245 | AWAIT_READY(slaveLost); |
| 246 | |
| 247 | JSON::Object stats = Metrics(); |
| 248 | EXPECT_EQ(1, stats.values["master/slave_removals"]); |
| 249 | EXPECT_EQ(1, stats.values["master/slave_removals/reason_unregistered"]); |
| 250 | EXPECT_EQ(0, stats.values["master/slave_removals/reason_unhealthy"]); |
| 251 | |
| 252 | driver.stop(); |
| 253 | driver.join(); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | // This test verifies that the slave rejects duplicate terminal |
nothing calls this directly
no test coverage detected