Beispiel #1
0
  def test_submit_cls_single(self) -> None:
    server = mock.Mock(spec=submit.GerritServer)
    server.fetch_change.side_effect = [
        # Initially, not on the queue.
        submit.Change('42', {}),
        # On the queue.
        submit.Change(
            '42', {'labels': {'Commit-Queue': {'approved': {'user_id': 33}}}}),
        submit.Change(
            '42', {'labels': {'Commit-Queue': {'approved': {'user_id': 33}}}}),
        # Retry.
        submit.Change('42', {}),
        # On the queue.
        submit.Change(
            '42', {'labels': {'Commit-Queue': {'approved': {'user_id': 33}}}}),
        # Submitted.
        submit.Change('42', {'status': 'MERGED'}),
    ]
    submit.submit_changes(
        util.FakeClock(),
        server, [submit.Change('42', {'submittable': True})],
        num_retries=2)

    # Should have added to CQ twice.
    server.set_cq_state.assert_called_with('42', 2)
    assert server.set_cq_state.call_count == 2
Beispiel #2
0
 def test_exponential_backoff(self) -> None:
     clock = util.FakeClock()
     backoff = util.ExponentialBackoff(clock,
                                       min_poll_seconds=1.,
                                       max_poll_seconds=10.,
                                       backoff=2.)
     backoff.wait()
     backoff.wait()
     backoff.wait()
     backoff.wait()
     backoff.wait()
     backoff.wait()
     self.assertEqual(clock.pauses, [1., 2., 4., 8., 10., 10.])
Beispiel #3
0
  def test_submit_cls_upgrade_to_approved(self) -> None:
    server = mock.Mock(spec=submit.GerritServer)
    server.fetch_change.side_effect = [
        # Initially, on the queue as recommended.
        submit.Change(
          '42', {'labels': {'Commit-Queue': {'recommended': {'user_id': 33}}}}),
        # Submitted.
        submit.Change('42', {'status': 'MERGED'}),
    ]
    submit.submit_changes(
        util.FakeClock(), server, [submit.Change('42', {'submittable': True})])

    # Should have added to CQ twice.
    server.set_cq_state.assert_called_with('42', 2)
    assert server.set_cq_state.call_count == 1
Beispiel #4
0
    def test_submit_cls_pretest(self) -> None:
        server = mock.Mock(spec=submit.GerritServer)
        server.fetch_change.side_effect = [
            submit.Change('42', {'status': 'NEW'}),
            submit.Change('42', {'status': 'MERGED'}),
            submit.Change('17', {'status': 'NEW'}),
            submit.Change('17', {'status': 'MERGED'}),
        ]
        submit.submit_changes(util.FakeClock(), server, [
            submit.Change('42', {'submittable': True}),
            submit.Change('17', {'submittable': True}),
        ])

        # Should have added to CQ twice.
        server.set_cq_state.assert_has_calls([
            mock.call('17', 1),
            mock.call('42', 2),
            mock.call('17', 2),
        ])
Beispiel #5
0
    def test_submit_cls_too_many_retries(self) -> None:
        server = mock.Mock(spec=submit.GerritServer)
        server.fetch_change.side_effect = [
            # Initially, not on the queue.
            submit.Change('42', {}),
            # When we next poll, we have been kicked out of the queue again. We should retry.
            submit.Change('42', {}),
            # And again. Retry again.
            submit.Change('42', {}),
            # And again. We should give up.
            submit.Change('42', {}),
        ]
        submit.submit_changes(util.FakeClock(),
                              server,
                              [submit.Change('42', {'submittable': True})],
                              num_retries=2)

        # Should have added to CQ twice.
        server.set_cq_state.assert_called_with('42', 2)
        assert server.set_cq_state.call_count == 3
Beispiel #6
0
 def test_submit_cls_empty(self) -> None:
     server = mock.Mock(spec=submit.GerritServer)
     submit.submit_changes(util.FakeClock(), server, [])