コード例 #1
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_wait_interval_truncated(self):
    agent = FakeAgent(time_series=[100] + [100 + i*5 for i in range(4)])
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    status.set_expected_iterations(10)
    status.wait(poll_every_secs=5, max_secs=12)
    self.assertEqual(3, status.got_sleep_count)
    # Last call truncated to the 2 secs remaining.
    self.assertEqual(2, status.got_sleep_secs)
コード例 #2
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_no_wait_with_max_secs_override(self):
    agent = FakeAgent()
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    # Even though we can wait, we wont because we're finished already.
    status.set_expected_iterations(0)
    status.wait(max_secs=10)
    self.assertEqual(1, status.got_refresh_count)
    self.assertEqual(0, status.got_sleep_count)
    self.assertTrue(status.finished)
    self.assertTrue(status.finished_ok)
コード例 #3
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_wait_interval(self):
    agent = FakeAgent()
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    status.set_expected_iterations(0)
    status.wait(poll_every_secs=60)
    self.assertEqual(0, status.got_sleep_count)

    status.got_sleep_count = 0
    status.set_expected_iterations(2)
    status.wait(poll_every_secs=60)
    self.assertEqual(2, status.got_sleep_count)
    self.assertEqual(60, status.got_sleep_secs)
コード例 #4
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_no_wait(self):
    agent = FakeAgent()
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    # Operation will finish right away on first refresh() call
    # so we shouldnt be waiting.
    status.set_expected_iterations(0)
    self.assertEqual(0, status.got_refresh_count)
    status.wait()
    self.assertEqual(1, status.got_refresh_count)
    self.assertTrue(status.finished)
    self.assertEqual(0, status.got_sleep_count)
    self.assertTrue(status.finished)
    self.assertTrue(status.finished_ok)
コード例 #5
0
 def test_raise_final_status_not_ok(self):
   attempt = agent_test_case.OperationContractExecutionAttempt('TestOp')
   operation = st.AgentOperation('TestStatus', agent=self.testing_agent)
   status = FakeStatus(operation)
   self.assertRaises(
       AssertionError,
       self.raise_final_status_not_ok, status, attempt)
コード例 #6
0
    def test_long_wait_cycle(self):
        agent = FakeAgent()
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        # Operation finishes after n waits.
        for i in range(2, 10):
            status.set_expected_iterations(i)
            status.got_sleep_count = 0
            status.got_sleep_secs = 0
            status.wait()
            self.assertEqual(i, status.got_sleep_count)
            self.assertEqual(status.default_wait_time_func(i),
                             status.got_sleep_secs)
コード例 #7
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_long_wait_cycle(self):
    agent = FakeAgent()
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    # Operation finishes after n waits.
    for i in range(2, 10):
      status.set_expected_iterations(i)
      status.got_sleep_count = 0
      status.got_sleep_secs = 0
      status.wait()
      self.assertEqual(i, status.got_sleep_count)
      self.assertEqual(status.default_wait_time_func(i),
                       status.got_sleep_secs)
コード例 #8
0
    def test_wait_interval_truncated(self):
        agent = FakeAgent(time_series=[100] + [100 + i * 5 for i in range(4)])
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        status.set_expected_iterations(10)
        status.wait(poll_every_secs=5, max_secs=12)
        self.assertEqual(3, status.got_sleep_count)
        # Last call truncated to the 2 secs remaining.
        self.assertEqual(2, status.got_sleep_secs)
コード例 #9
0
    def test_no_wait_with_max_secs_override(self):
        agent = FakeAgent()
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        # Even though we can wait, we wont because we're finished already.
        status.set_expected_iterations(0)
        status.wait(max_secs=10)
        self.assertEqual(1, status.got_refresh_count)
        self.assertEqual(0, status.got_sleep_count)
        self.assertTrue(status.finished)
        self.assertTrue(status.finished_ok)
コード例 #10
0
    def test_one_wait_cycle(self):
        agent = FakeAgent()
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        # Operation can finish after one wait.
        status.set_expected_iterations(1)
        self.assertFalse(status.finished)
        self.assertFalse(status.finished_ok)
        status.wait()
        self.assertTrue(status.finished)
        self.assertTrue(status.finished_ok)
        self.assertEqual(2, status.got_refresh_count)
        self.assertEqual(1, status.got_sleep_count)
        self.assertEqual(status.default_wait_time_func(1),
                         status.got_sleep_secs)
コード例 #11
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_one_wait_cycle(self):
    agent = FakeAgent()
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    # Operation can finish after one wait.
    status.set_expected_iterations(1)
    self.assertFalse(status.finished)
    self.assertFalse(status.finished_ok)
    status.wait()
    self.assertTrue(status.finished)
    self.assertTrue(status.finished_ok)
    self.assertEqual(2, status.got_refresh_count)
    self.assertEqual(1, status.got_sleep_count)
    self.assertEqual(status.default_wait_time_func(1), status.got_sleep_secs)
コード例 #12
0
    def test_no_wait(self):
        agent = FakeAgent()
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        # Operation will finish right away on first refresh() call
        # so we shouldnt be waiting.
        status.set_expected_iterations(0)
        self.assertEqual(0, status.got_refresh_count)
        status.wait()
        self.assertEqual(1, status.got_refresh_count)
        self.assertTrue(status.finished)
        self.assertEqual(0, status.got_sleep_count)
        self.assertTrue(status.finished)
        self.assertTrue(status.finished_ok)
コード例 #13
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_wait_timeout_with_override(self):
    time_series = [100] + [i + 100 for i in range(10)]
    agent = FakeAgent(time_series)
    agent.default_max_wait_secs = 5
    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    # Override default wait time.
    # We're telling the status to expect more iterations than
    # it will actually get. All this means is it wont mark
    # the status as being finished.
    status.set_expected_iterations(10)
    status.wait(max_secs=2)
    status.got_sleep_count = 0
    self.assertFalse(status.finished)
    self.assertEqual(8 - 1, status.calls_remaining)

    # Show timeout doesnt prevent us from waiting until completion later.
    agent.time_series = [200] + [i + 200 for i in range(9)]
    status.set_expected_iterations(9)
    status.wait(max_secs=10)
    self.assertEqual(9, status.got_sleep_count)
    self.assertEqual(status.default_wait_time_func(9),
                     status.got_sleep_secs)
    self.assertEqual(-1, status.calls_remaining)
コード例 #14
0
    def test_wait_timeout_with_override(self):
        time_series = [100] + [i + 100 for i in range(10)]
        agent = FakeAgent(time_series)
        agent.default_max_wait_secs = 5
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        # Override default wait time.
        # We're telling the status to expect more iterations than
        # it will actually get. All this means is it wont mark
        # the status as being finished.
        status.set_expected_iterations(10)
        status.wait(max_secs=2)
        status.got_sleep_count = 0
        self.assertFalse(status.finished)
        self.assertEqual(8 - 1, status.calls_remaining)

        # Show timeout doesnt prevent us from waiting until completion later.
        agent.time_series = [200] + [i + 200 for i in range(9)]
        status.set_expected_iterations(9)
        status.wait(max_secs=10)
        self.assertEqual(9, status.got_sleep_count)
        self.assertEqual(status.default_wait_time_func(9),
                         status.got_sleep_secs)
        self.assertEqual(-1, status.calls_remaining)
コード例 #15
0
 def test_status_constructor(self):
     agent = FakeAgent()
     operation = st.AgentOperation('TestStatus', agent=agent)
     status = FakeStatus(operation)
     self.assertFalse(status.finished)
コード例 #16
0
    def test_wait_interval(self):
        agent = FakeAgent()
        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        status.set_expected_iterations(0)
        status.wait(poll_every_secs=60)
        self.assertEqual(0, status.got_sleep_count)

        status.got_sleep_count = 0
        status.set_expected_iterations(2)
        status.wait(poll_every_secs=60)
        self.assertEqual(2, status.got_sleep_count)
        self.assertEqual(60, status.got_sleep_secs)
コード例 #17
0
ファイル: base_agent_test.py プロジェクト: ewiseblatt/citest
  def test_wait_timeout(self):
    time_series = [100] + [i + 100 for i in range(6)]
    agent = FakeAgent(time_series=time_series)
    agent.default_max_wait_secs = 5

    operation = st.AgentOperation('TestStatus', agent=agent)
    status = FakeStatus(operation)

    status.set_expected_iterations(20)
    status.wait()
    self.assertFalse(status.finished)
    self.assertFalse(status.finished_ok)
    self.assertEquals(1 + 5, status.got_refresh_count)
    self.assertEqual(15 - 1, status.calls_remaining)
    self.assertEqual(5, status.got_sleep_count)
    self.assertEqual(1, status.got_sleep_secs)


    # Wait another 5 seconds to show we can continue waiting longer.
    agent.time_series = [200] + [i + 200 for i in range(6)]
    status.got_sleep_count = 0
    status.got_sleep_secs = 0
    status.set_expected_iterations(15)
    status.wait()
    self.assertEqual(10 - 1, status.calls_remaining)
    self.assertEqual(5, status.got_sleep_count)
    self.assertEqual(1, status.got_sleep_secs)
コード例 #18
0
    def test_wait_timeout(self):
        time_series = [100] + [i + 100 for i in range(6)]
        agent = FakeAgent(time_series=time_series)
        agent.default_max_wait_secs = 5

        operation = st.AgentOperation('TestStatus', agent=agent)
        status = FakeStatus(operation)

        status.set_expected_iterations(20)
        status.wait()
        self.assertFalse(status.finished)
        self.assertFalse(status.finished_ok)
        self.assertEquals(1 + 5, status.got_refresh_count)
        self.assertEqual(15 - 1, status.calls_remaining)
        self.assertEqual(5, status.got_sleep_count)
        self.assertEqual(1, status.got_sleep_secs)

        # Wait another 5 seconds to show we can continue waiting longer.
        agent.time_series = [200] + [i + 200 for i in range(6)]
        status.got_sleep_count = 0
        status.got_sleep_secs = 0
        status.set_expected_iterations(15)
        status.wait()
        self.assertEqual(10 - 1, status.calls_remaining)
        self.assertEqual(5, status.got_sleep_count)
        self.assertEqual(1, status.got_sleep_secs)