Ejemplo n.º 1
0
    def test_single_stage_dispatch(self):
        os1 = actions.ActionAppend1.get_option_set()
        os2 = actions.ActionAppend2.get_option_set()
        os3 = actions.ActionAppend3.get_option_set()

        cnt1 = len(actions.ActionAppend1.OPTION_SET)
        cnt2 = len(actions.ActionAppend2.OPTION_SET)
        cnt3 = len(actions.ActionAppend3.OPTION_SET)

        expected_cnt = cnt1 * cnt2 * cnt3

        total_count, error_count, _, elapsed, states, _, _ = \
                runner.run_tests([actions.ActionAppend1,
                                  actions.ActionAppend2,
                                  actions.ActionAppend3],
                                 gather_states=True,
                                 state={},
                                 verbose=True)

        self.assertEqual(total_count, expected_cnt)
        self.assertEqual(error_count, 0)

        all_states = []
        for worker_states in states:
            all_states.extend([inner['inner'] for inner in worker_states])
        all_states.sort()

        current_idx = 0
        for i in range(cnt1):
            for j in range(cnt2):
                for k in range(cnt3):
                    expected = [i, j, k]
                    self.assertEqual(expected, all_states[current_idx])
                    current_idx += 1
Ejemplo n.º 2
0
 def test_fail_count(self):
     results = runner.run_tests([
         actions.ActionFail,
     ])
     self.assertEqual(results.error_count, 1)
     self.assertEqual(results.walk_count, 1)
     self.assertEqual(len(results.failed_tests), 1)
Ejemplo n.º 3
0
    def test_multistage(self):
        cnt1 = len(actions.ActionAppend1.OPTION_SET)
        cnt2 = len(actions.ActionAppend2.OPTION_SET)
        cnt3 = len(actions.ActionAppend3.OPTION_SET)

        sp_cnt1 = len(actions.SerialActionAppend1.OPTION_SET)
        sp_cnt2 = len(actions.SerialActionAppend2.OPTION_SET)

        expected_cnt = cnt1 * cnt2 * sp_cnt1 * cnt3 * sp_cnt2

        action_classes = [
            actions.ActionAppend1,
            actions.ActionAppend2,
            actions.SerialActionAppend1,
            actions.ActionAppend3,
            actions.SerialActionAppend2,
        ]

        log_dir = self._get_temp_dir()

        walk_count, error_count, segment_count, elapsed, states, _, _ = \
                runner.run_tests(action_classes,
                                 gather_states=True,
                                 verbose=True,
                                 state={},
                                 # (assumes we are running
                                 # everything locally)
                                 log_dir=log_dir,
                                )

        self.assertEqual(walk_count, expected_cnt)
        # 3 below from: segment before sp1, segment between sp1 and sp2, and
        # after sp2.
        self.assertEqual(segment_count, expected_cnt * 3)
        self.assertEqual(error_count, 0)

        all_states = []

        for worker_states in states:
            for walk_state in worker_states:
                inner = walk_state['inner']
                inner.append(walk_state['sp_value'])
                all_states.append(inner)
        all_states.sort()

        current_idx = 0
        for i in range(cnt1):
            for j in range(cnt2):
                for k in range(sp_cnt1):
                    for l in range(cnt3):
                        for m in range(sp_cnt2):
                            expected = [i, j, k, l, m]
                            self.assertEqual(expected, all_states[current_idx])
                            current_idx += 1
Ejemplo n.º 4
0
    def test_multistage_leading_syncpoint(self):
        cnt1 = len(actions.ActionAppend1.OPTION_SET)
        cnt2 = len(actions.ActionAppend2.OPTION_SET)

        sp_cnt1 = len(actions.SerialActionAppend1.OPTION_SET)
        sp_cnt2 = len(actions.SerialActionAppend2.OPTION_SET)

        expected_cnt = sp_cnt1 * cnt1 * cnt2 * sp_cnt2

        log_dir = self._get_temp_dir()

        walk_count, error_count, segment_count, elapsed, states, _, _ = \
                runner.run_tests([
                                  actions.SerialActionAppend1,
                                  actions.ActionAppend1,
                                  actions.ActionAppend2,
                                  actions.SerialActionAppend2,
                                 ],
                                 gather_states=True,
                                 log_dir=log_dir,
                                 verbose=True,
                                 state={},
                                )

        self.assertEqual(walk_count, expected_cnt)
        # 2 below from: segment between sp1 and sp2, and
        # after sp2.
        self.assertEqual(segment_count, expected_cnt * 2)
        self.assertEqual(error_count, 0)

        all_states = []

        for worker_states in states:
            for walk_state in worker_states:
                inner = walk_state['inner']
                inner.append(walk_state['sp_value'])
                all_states.append(inner)
        all_states.sort()

        current_idx = 0
        for i in range(sp_cnt1):
            for j in range(cnt1):
                for k in range(cnt2):
                    for l in range(sp_cnt2):
                        expected = [i, j, k, l]
                        self.assertEqual(expected, all_states[current_idx])
                        current_idx += 1
Ejemplo n.º 5
0
    def test_dont_try(self):
        log_dir = self._get_temp_dir()
        action_classes = [
            actions.ActionAppendList1, actions.SerialActionDontTryUpdate,
            actions.ActionAppendList2
        ]
        state = []
        walk_count, error_count, segment_count, elapsed, states, _, _ = \
                runner.run_tests(action_classes,
                                 gather_states=True,
                                 log_dir=log_dir,
                                 verbose=2,
                                 state=state,
                                )

        expected_cnt = (len(actions.ActionAppendList1.OPTIONS) *
                        len(actions.SerialActionDontTryUpdate.OPTIONS) *
                        len(actions.ActionAppendList2.OPTIONS))
        self.assertEqual(walk_count, expected_cnt)
        self.assertEqual(error_count, 0)

        # Split above/below the sync point
        self.assertEqual(segment_count, expected_cnt * 2)

        all_states = []
        for worker_states in states:
            for walk_state in worker_states:
                all_states.append(walk_state)
        all_states.sort()

        current_idx = 0
        for opt1 in actions.ActionAppendList1.OPTIONS:
            for opt2 in actions.ActionAppendList2.OPTIONS:
                expected = [opt1, opt2]
                for _ in range(len(actions.SerialActionDontTryUpdate.OPTIONS)):
                    self.assertEqual(expected, all_states[current_idx])
                    current_idx += 1
Ejemplo n.º 6
0
    def test_no_state_provided(self):
        runner.run_tests([actions.ActionExpectNoState], gather_states=True)

        runner.run_tests([actions.ActionExpectNoState], gather_states=False)
Ejemplo n.º 7
0
    def test_walk_replay(self):
        log_dir = tempfile.mkdtemp()

        walk_order = [actions.ActionSingleton1,
                      actions.ActionSingleton2,
                      actions.SerialActionSingleton1,
                      actions.ActionSingleton3]
        # See classes.py
        expected = [1, 2, 0, 3]

        state = {}
        walk_count, error_count, _, _, states, logs, _ = \
                runner.run_tests(walk_order,
                                 verbose=2,
                                 log_dir=log_dir,
                                 state=state,
                                 gather_states=True)
        self.assertEqual(walk_count, 1)
        self.assertEqual(error_count, 0)

        # Single worker
        self.assertEqual(len(states), 1)
        # Single walk on that worker
        worker_states = states[0]
        self.assertEqual(len(worker_states), 1)
        state = worker_states[0]
        state = state['inner']
        self.assertEqual(state, expected)

        trace_logs = [log_locs[1] for log_locs in
                      logs['remote'].values()]
        # Maps walk_id->list of stuff
        walks = {}
        for trace_log in trace_logs:
            with open(trace_log, 'r') as f:
                for line in f:
                    record = encode.decode(line)
                    walk_id = record['walk_id']
                    current_walk = record['walk']
                    serial_action = record['serial_action']

                    if walk_id not in walks:
                        walks[walk_id] = []
                    walks[walk_id].append((current_walk, serial_action))
        # Checking my assumptions
        self.assertEqual(len(walks), 1)

        walk_to_replay = walk.Walk()
        for segment in list(walks.values())[0]:
            walk_segment = segment[0]
            serial_action = segment[1]
            if serial_action:
                walk_to_replay.append(serial_action)
            walk_to_replay += walk_segment

        # Replay walk directly
        state = {}
        runner.replay_walk(walk_to_replay, state=state)
        self.assertTrue('inner' in state)
        self.assertEqual(state['inner'], expected)

        # Now let's test the replay lib
        state = {}
        state = replay.replay_walk_by_id(logs, walk_id, step=False,
                                         state=state)
        self.assertTrue('inner' in state)
        self.assertEqual(state['inner'], expected)

        shutil.rmtree(log_dir)