예제 #1
0
def test_can_start_gridappsd_within_dependency_context_manager_all_cleanup():

    Containers.reset_all_containers()

    with run_dependency_containers(True) as cont:
        # True in this method will remove the containsers
        with run_gridappsd_container(True) as dep_con:
            # Default cleanup is true within run_gridappsd_container method
            timeout = 0
            gapps = None
            time.sleep(10)
            while timeout < 30:
                try:
                    gapps = GridAPPSD()
                    gapps.connect()
                    break
                except:
                    time.sleep(1)
                    timeout += 1

            assert gapps
            assert gapps.connected

    # Filter out the two config containers that we start up for volume data.
    containers = [
        x.name for x in Containers.container_list() if "config" not in x.name
    ]
    assert not len(containers)
예제 #2
0
def gridappsd_client(docker_dependencies):
    with run_gridappsd_container(True):
        gappsd = GridAPPSD()
        gappsd.connect()
        assert gappsd.connected

        yield gappsd

        gappsd.disconnect()
예제 #3
0
def gridappsd_client(request, docker_dependencies):
    with run_gridappsd_container(stop_after=STOP_CONTAINER_AFTER_TEST):
        gappsd = GridAPPSD()
        gappsd.connect()
        assert gappsd.connected
        models = gappsd.query_model_names()
        assert models is not None
        if request.cls is not None:
            request.cls.gridappsd_client = gappsd
        yield gappsd

        gappsd.disconnect()
예제 #4
0
def test_multiple_runs_in_a_row_with_dependency_context_manager():

    Containers.reset_all_containers()

    with run_dependency_containers():
        pass

    containers = [
        x for x in Containers.container_list() if "config" not in x.name
    ]
    assert len(containers) == 5

    with run_gridappsd_container():
        timeout = 0
        gapps = None

        while timeout < 30:
            try:
                gapps = GridAPPSD()
                gapps.connect()
                break
            except:
                time.sleep(1)
                timeout += 1

        assert gapps
        assert gapps.connected

    with run_gridappsd_container():
        timeout = 0
        gapps = None
        time.sleep(10)
        while timeout < 30:
            try:
                gapps = GridAPPSD()
                gapps.connect()
                break
            except:
                time.sleep(1)
                timeout += 1

        assert gapps
        assert gapps.connected
    # pprint(headers)
    # pprint(message)


for cfile in data_tests:
    config_file = str(TEST_DATA_DIR.joinpath(cfile))
    run_config = merge_with_simulation_config(config_file)

    # from pprint import pprint
    # pprint(config['gridappsd'])
    with run_containers(config, stop_after=True) as containers:
        # Watches the log on the container for the MYSQL data.
        containers.wait_for_log_pattern("gridappsd", "MYSQL")

        gappsd = GridAPPSD()
        gappsd.connect()
        assert gappsd.connected

        time.sleep(10)
        sim = Simulation(gappsd, run_config=run_config)

        sim.add_onstart_callback(onstart)
        sim.add_oncomplete_callback(onfinish)
        sim.add_ontimestep_callback(ontimestep)
        sim.add_onmesurement_callback(onmeasurement)

        sim.start_simulation()
        sim.pause()
        gappsd.subscribe(t.simulation_output_topic(sim.simulation_id), onsimulationoutput)
        gappsd.subscribe(t.application_output_topic(GRIDAPPSD_SERVICE_ID, sim.simulation_id), onsensoroutput)
        time.sleep(10)