Esempio n. 1
0
def run_test(build_directory, yaml_file, node_exe, name_filter=None):

    # Read YAML file
    with open(yaml_file, 'r') as stream:
        try:
            all_yaml = yaml.safe_load_all(stream)

            # Parse yaml documents as tests (sequentially)
            for test in all_yaml:
                # Get test setup conditions
                setup_conditions = yaml_extract(test, 'setup_conditions')

                # Check if name is not filtered out
                if name_filter is not None:
                    name = yaml_extract(setup_conditions, 'test_name')
                    if name not in name_filter:
                        continue

                # Create a new test instance
                description = yaml_extract(test, 'test_description')
                output("\n=================================================")
                output("Test: {}".format(description))
                output("=================================================\n")

                if "DISABLED" in description:
                    output("Skipping disabled test")
                    continue

                # Create a test instance
                test_instance = create_test(setup_conditions, build_directory,
                                            node_exe, yaml_file)

                # Configure the test - this will start the nodes asynchronously
                setup_test(setup_conditions, test_instance)

                # Run the steps in the test
                run_steps(yaml_extract(test, 'steps'), test_instance)

                test_instance.stop()
        except Exception as e:
            print('Failed to parse yaml or to run test! Error: "{}"'.format(e))
            traceback.print_exc()
            test_instance.stop()
            test_instance.dump_debug()
            sys.exit(1)

    output("\nAll end to end tests have passed :)")
Esempio n. 2
0
def setup_test(test_yaml, test_instance):
    output("Setting up test: {}".format(test_yaml))

    test_name = yaml_extract(test_yaml, 'test_name',
                             expected=True, expect_type=str)
    number_of_nodes = yaml_extract(
        test_yaml, 'number_of_nodes', expected=True, expect_type=int)
    node_load_directory = yaml_extract(
        test_yaml, 'node_load_directory', expected=False, expect_type=dict)
    node_connections = yaml_extract(
        test_yaml, 'node_connections', expected=False, expect_type=list)
    mining_nodes = yaml_extract(test_yaml, 'mining_nodes',
                                expected=False, expect_type=list, default=[])
    max_test_time = yaml_extract(test_yaml, 'max_test_time',
                                 expected=False, expect_type=int, default=10)
    pos_mode = yaml_extract(test_yaml, 'pos_mode', expected=False,
                            expect_type=bool, default=False)
    num_lanes = yaml_extract(test_yaml, 'lanes', expected=False,
                             expect_type=int, default=1)

    test_instance._number_of_nodes = number_of_nodes
    test_instance._node_load_directory = node_load_directory
    test_instance._node_connections = node_connections
    test_instance._nodes_are_mining = mining_nodes
    test_instance._max_test_time = max_test_time
    test_instance._pos_mode = pos_mode
    test_instance._lanes = num_lanes

    # Watchdog will trigger this if the tests exceeds allowed bounds. Note stopping the test cleanly is
    # necessary to preserve output logs etc.
    def clean_shutdown():
        output(
            "***** Shutting down test due to failure!. Debug YAML: {} *****\n".format(test_yaml))
        test_instance.stop()
        test_instance.dump_debug()
        os._exit(1)

    watchdog = TimerWatchdog(
        time=max_test_time,
        name=test_name,
        task="End test and cleanup",
        callback=clean_shutdown)
    watchdog.start()

    test_instance._watchdog = watchdog

    # This shouldn't take a long time since nodes are started asynchronously
    test_instance.run()
Esempio n. 3
0
def create_test(setup_conditions, build_directory, node_exe, yaml_file):
    test_type = yaml_extract(
        setup_conditions, 'test_type', expected=False, expect_type=str)

    # default case
    if test_type is None:
        return ConstellationTestCase(build_directory, node_exe, yaml_file)

    if test_type == "Constellation":
        return ConstellationTestCase(build_directory, node_exe, yaml_file)
    elif test_type == "DmlfEtch":
        return DmlfEtchTestCase(build_directory, node_exe, yaml_file)
    else:
        raise ValueError("Unkown test type: {}".format(test_type))