Source of file RollbackStepTest.php
Size: 4,653 Bytes - Last Modified: 2021-12-23T10:29:15+00:00
/var/www/docs.ssmods.com/process/src/tests/RollbackStepTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 | <?php /** * Test rollback of deployments */ class RollbackStepTest extends PipelineTest { protected static $fixture_file = 'PipelineTest.yml'; /** * Makes the dummy deployment step * * @return Pipeline */ public function getDummyPipeline($restoreDB = true) { // Get default backups $previous = DNDeployment::create(); $previous->write(); $current = DNDeployment::create(); $current->write(); $snapshot = DNDataTransfer::create(); $snapshot->write(); // Setup default pipeline $pipeline = $this->objFromFixture('Pipeline', 'testpipesmoketest'); $pipeline->Config = serialize(array( 'RollbackStep1' => array( 'Class' => 'RollbackStep', 'RestoreDB' => $restoreDB, 'MaxDuration' => '3600' ) )); $pipeline->PreviousDeploymentID = $previous->ID; $pipeline->CurrentDeploymentID = $current->ID; $pipeline->PreviousSnapshotID = $snapshot->ID; $pipeline->write(); return $pipeline; } public function testSuccessful() { $pipeline = $this->getDummyPipeline(); // Start failure $pipeline->markFailed(); $step = $pipeline->RollbackStep1(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertEquals('Deployment', $step->Doing); $this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet // Mark the service as completed and check result $deployment = $step->RollbackDeployment(); $deployment->markFinished(); // Re-enter step as if called from checkPipelineStatus PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Started', $step->Status); $this->assertEquals('Snapshot', $step->Doing); $this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet // Mark the snapshot as completed and check result $snapshot = $step->RollbackDatabase(); $snapshot->markFinished(); // Re-enter step as if called from checkPipelineStatus PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Finished', $step->Status); // confirm the maintenace page has been left up for a failed rollback $this->assertFalse(PipelineTest_MockLog::has_message('Enabling maintenance page for failed rollback')); // The deployment was considered a failure $this->assertEquals('Failed', $pipeline->CurrentDeployment()->Status); } /** * Test rollback without DB restoration */ public function testNoDB() { $pipeline = $this->getDummyPipeline(false); // Start failure $pipeline->markFailed(); $step = $pipeline->RollbackStep1(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertEquals('Deployment', $step->Doing); // Mark the service as completed and check result $deployment = $step->RollbackDeployment(); $deployment->markFinished(); // Re-enter step as if called from checkPipelineStatus PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Finished', $step->Status); } /** * Test failure at the snapshot step */ public function testSnapshotFailure() { $pipeline = $this->getDummyPipeline(); // Start failure $pipeline->markFailed(); $step = $pipeline->RollbackStep1(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertEquals('Deployment', $step->Doing); // Mark the service as completed and check result $deployment = $step->RollbackDeployment(); $deployment->markFinished(); // Re-enter step as if called from checkPipelineStatus PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Started', $step->Status); $this->assertEquals('Snapshot', $step->Doing); // Mark the snapshot as completed and check result $snapshot = $step->RollbackDatabase(); $snapshot->markFailed(); // Re-enter step as if called from checkPipelineStatus PipelineTest_MockLog::clear(); $step->start(); $this->assertEquals('Failed', $step->Status); } /** * Test failure at the deployment step */ public function testDeploymentFailure() { $pipeline = $this->getDummyPipeline(); // Start failure $pipeline->markFailed(); $step = $pipeline->RollbackStep1(); // Assert not error at startup $this->assertEquals('Started', $step->Status); $this->assertEquals('Deployment', $step->Doing); // Mark the service as completed and check result $deployment = $step->RollbackDeployment(); $deployment->markFailed(); // Confirm that the maintenance page is not disabled $this->assertNotLogged('Maintenance page disabled'); // The deployment was considered a failure $this->assertEquals('Failed', $pipeline->CurrentDeployment()->Status); } } |