@@ -3,6 +3,7 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import candidate_queue as queue
|
||||
import release_handoff as h
|
||||
|
||||
|
||||
@@ -33,6 +34,48 @@ class ReleaseHandoffTest(unittest.TestCase):
|
||||
with self.assertRaisesRegex(h.cd.CDError, error):
|
||||
h.review_identity(self.task, [row], 'comment')
|
||||
|
||||
def test_busy_candidate_waits_on_original_task_without_dispatch(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, patch.object(h.coordinator, 'STATE', Path(tmp)), \
|
||||
patch.object(h, 'resolve', return_value=('a' * 40, '30')), \
|
||||
patch.object(h.coordinator, 'add_comment'), patch.object(h.coordinator, 'queue') as dispatch:
|
||||
task_id = '00000001-1111-2222-3333-444444444444'
|
||||
event = '00000002-1111-2222-3333-444444444444'
|
||||
slot = Path(tmp) / 'another' / 'compose.json'
|
||||
slot.parent.mkdir()
|
||||
slot.touch()
|
||||
first = h.preflight({'id': task_id}, event)
|
||||
second = h.preflight({'id': task_id}, event)
|
||||
self.assertEqual(first, second)
|
||||
self.assertEqual(first['state'], 'waiting_for_slot')
|
||||
self.assertEqual(len(list((Path(tmp) / 'waiting').glob('*.json'))), 1)
|
||||
dispatch.assert_not_called()
|
||||
|
||||
def test_waiter_dispatches_once_when_slot_is_free(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, patch.object(h.coordinator, 'STATE', Path(tmp)), \
|
||||
patch.object(h, 'resolve', return_value=('a' * 40, '30')), \
|
||||
patch.object(h.assistant, 'task_record', return_value={'id': 'task'}), \
|
||||
patch.object(h.assistant.worker, 'main_site_sha', return_value='b' * 40), \
|
||||
patch.object(h.candidate, 'git', return_value='b' * 40), \
|
||||
patch.object(h.coordinator, 'add_comment'), \
|
||||
patch.object(h, 'prepare_from_review', return_value={'url': 'https://example.test/run/1'}) as build:
|
||||
h.preflight({'id': 'task'}, 'event')
|
||||
self.assertEqual(queue.drain(), 'dispatched')
|
||||
self.assertEqual(queue.drain(), 'idle')
|
||||
build.assert_called_once_with({'id': 'task'}, 'event')
|
||||
|
||||
def test_active_qa_slot_is_preserved(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, patch.object(h.coordinator, 'STATE', Path(tmp)), \
|
||||
patch.object(h.assistant, 'task_record', return_value={'status': {'id': 'testing'}}), \
|
||||
patch.object(h.cd, 'run') as docker:
|
||||
root = Path(tmp)
|
||||
(root / 'waiting').mkdir()
|
||||
h.cd.record(root / 'waiting/event.json', {'state': 'waiting_for_slot'})
|
||||
(root / 'slot').mkdir()
|
||||
(root / 'slot/compose.json').touch()
|
||||
h.cd.record(root / 'slot/ready.json', {'task': 'task'})
|
||||
self.assertEqual(queue.drain(), 'occupied')
|
||||
docker.assert_not_called()
|
||||
|
||||
def test_owner_approval_is_bound_to_exact_preview_and_parent(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, patch.object(h, 'DIRECTORY', Path(tmp)):
|
||||
saved = {'content': 'reviewed scope', 'comment': 'preview', 'plan': {'frozen': True}}
|
||||
|
||||
Reference in New Issue
Block a user