def test_rollback_migration_failure(self): migration_name = "test_with_rollback_exception" create_async_migration(name=migration_name) self.migration.sec.reset_count() migration_successful = start_async_migration(migration_name) self.assertEqual(migration_successful, True) sm = AsyncMigration.objects.get(name=migration_name) attempt_migration_rollback(sm) sm.refresh_from_db() self.assertEqual(sm.status, MigrationStatus.Errored) self.assertEqual(sm.current_operation_index, 1)
def test_force_stop_migration(self, mock_app_control_revoke): sm = create_async_migration() force_stop_migration(sm, rollback=False) sm.refresh_from_db() mock_app_control_revoke.assert_called_once() self.assertEqual(sm.status, MigrationStatus.Errored) errors = AsyncMigrationError.objects.filter(async_migration=sm) self.assertEqual(errors.count(), 1) self.assertEqual(errors[0].description, "Force stopped by user")
def test_complete_migration(self): sm = create_async_migration() complete_migration(sm) sm.refresh_from_db() self.assertEqual(sm.status, MigrationStatus.CompletedSuccessfully) self.assertGreater(sm.finished_at, datetime.now(timezone.utc) - timedelta(hours=1)) self.assertEqual(sm.progress, 100) errors = AsyncMigrationError.objects.filter(async_migration=sm) self.assertEqual(errors.count(), 0)
def test_process_error(self, _): sm = create_async_migration() process_error(sm, "some error") process_error(sm, "second error") sm.refresh_from_db() self.assertEqual(sm.status, MigrationStatus.Errored) self.assertGreater(sm.finished_at, datetime.now(timezone.utc) - timedelta(hours=1)) errors = AsyncMigrationError.objects.filter( async_migration=sm).order_by("created_at") self.assertEqual(errors.count(), 2) self.assertEqual(errors[0].description, "some error") self.assertEqual(errors[1].description, "second error")
def setUp(self) -> None: create_async_migration(name="test", description=TEST_MIGRATION_DESCRIPTION) return super().setUp()
def setUp(self): self.migration = Migration() self.TEST_MIGRATION_DESCRIPTION = self.migration.description create_async_migration(name="test", description=self.TEST_MIGRATION_DESCRIPTION) return super().setUp()
def test_trigger_migration(self, mock_run_async_migration): sm = create_async_migration() trigger_migration(sm) mock_run_async_migration.assert_called_once()