def test_check_service(tmpdir, monkeypatch): with tmpdir.as_cwd(): with patch.object( sys, "argv", ["ert3", "service", "check", "storage", "--timeout", "10"]): with Storage.start_server(): ert3.console._console._main()
def test_cli_local_test_run(tmpdir): with chdir(tmpdir): with Storage.start_server(): args = ["ert3", "init", "--example", "polynomial"] with patch.object(sys, "argv", args): ert3.console._console._main() os.chdir("polynomial") # Error testing is performed in this context to reduce # test time as a full storage server is involved. with pytest.raises(ert.exceptions.ExperimentError): with patch.object( sys, "argv", ["ert3", "run", "sensitivity", "--local-test-run"] ): ert3.console._console._main() with patch.object( sys, "argv", ["ert3", "run", "evaluation", "--local-test-run"] ): ert3.console._console._main() experiments = [ experiment for experiment in ert.storage.get_experiment_names( workspace_name="polynomial" ) if experiment.startswith("evaluation-") ] assert len(experiments) == 1 run_id = experiments[0].split("-")[1] assert pathlib.Path(f"local-test-run-{run_id}/output.json").exists()
def start_ert_server(mode: str): if mode in ("api", "vis") or not FeatureToggling.is_enabled("new-storage"): yield return with Storage.start_server(): yield
def run_ert_storage(args): kwargs = {"res_config": args.config} if args.database_url is not None: kwargs["database_url"] = args.database_url with Storage.start_server(**kwargs) as server: server.wait()
def test_cli_local_test_run_specific_realization(tmpdir): with chdir(tmpdir): with Storage.start_server(): args = ["ert3", "init", "--example", "polynomial"] with patch.object(sys, "argv", args): ert3.console._console._main() os.chdir("polynomial") with pytest.raises(ert.exceptions.ExperimentError): with patch.object( sys, "argv", ["ert3", "run", "evaluation", "--realization", "2"] ): ert3.console._console._main() poly_size = yaml.safe_load( pathlib.Path("experiments/evaluation/ensemble.yml").read_text( encoding="utf-8" ) )["size"] not_existing_realization = poly_size # zero-indexed realizations with pytest.raises( ert.exceptions.ConfigValidationError, match="Realization out of ensemble bounds", ): assert not_existing_realization > poly_size - 1 with patch.object( sys, "argv", [ "ert3", "run", "evaluation", "--local-test-run", "--realization", str(not_existing_realization), ], ): ert3.console._console._main() with patch.object( sys, "argv", ["ert3", "run", "evaluation", "--local-test-run", "--realization", "2"], ): ert3.console._console._main() experiments = [ experiment for experiment in ert.storage.get_experiment_names( workspace_name="polynomial" ) if experiment.startswith("evaluation-") ] assert len(experiments) == 1 run_id = experiments[0].split("-")[1] assert pathlib.Path(f"local-test-run-{run_id}/output.json").exists()
def workspace_integration(tmpdir): from ert_shared.services import Storage workspace_dir = pathlib.Path(tmpdir / "polynomial") workspace_dir.mkdir() with chdir(workspace_dir): with Storage.start_server(): workspace_obj = ert3.workspace.initialize(workspace_dir) ert.storage.init(workspace_name=workspace_obj.name) yield workspace_obj
def test_integration_timeout(tmp_path, monkeypatch): """Try to start the server but give it too small time to get ready and expect a timeout""" monkeypatch.chdir(tmp_path) with pytest.raises(TimeoutError): # Note timeout-value here in context of note above with Storage.start_server(timeout=0.01) as server: requests.get(f"{server.fetch_url()}/healthcheck", auth=server.fetch_auth()) assert not (tmp_path / "storage_server.json").exists()
def test_integration(tmp_path, monkeypatch): """Actually start the server, wait for it to be online and do a health check""" monkeypatch.chdir(tmp_path) # Note: Sqlite needs at least 4-5 seconds to spin up even on # an unloaded M1-based Mac using local disk. On the CI-server # we have less control of available resources, so set timeout- # value large to allow time for sqlite to get ready with Storage.start_server(timeout=120) as server: resp = requests.get(f"{server.fetch_url()}/healthcheck", auth=server.fetch_auth()) assert "ALL OK!" in resp.json() with Storage.session() as session: session.get("/healthcheck") assert not (tmp_path / "storage_server.json").exists()
def get_info(): from ert_shared.services import Storage with Storage.start_server() as service: yield service.fetch_url(), service.fetch_auth()[1]