diff --git a/tests/integration/test_artifacts.py b/tests/integration/test_artifacts.py index 147b940..462fdb6 100644 --- a/tests/integration/test_artifacts.py +++ b/tests/integration/test_artifacts.py @@ -6,6 +6,7 @@ import os import shutil +import threading from pathlib import Path import pygit2 @@ -226,3 +227,36 @@ def test_iter() -> None: assert pkgs[1].version == "v2.0.1" assert pkgs[2].name == "pck3" assert pkgs[2].version is None + + +# pygit2 protects us against producing diverging histories anyway: +# _pygit2.GitError: failed to create commit: current tip is not the first +# parent +# but the test is nice reassurance. +def test_simultaneous_commit(): + parallelism = 100 + ad = new_test_artifacts() + artifacts: Artifacts = ad["artifacts"] + initial_commit_oid = ad["initial_commit_oid"] + + new_tree, _ = add_test_file_to_repo(artifacts) + + e = threading.Event() + + def fn(i: int): + e.wait() + artifacts.commit_and_push(new_tree, f"I am thread {i}") + + threads = [ + threading.Thread(target=fn, args=[i]) for i in range(parallelism) + ] + for thread in threads: + thread.start() + e.set() + for thread in threads: + thread.join() + + commit = artifacts.repo.head.peel(pygit2.Commit) + for _ in range(parallelism): + commit = commit.parents[0] + assert commit.oid == initial_commit_oid diff --git a/tests/integration/test_environment.py b/tests/integration/test_environment.py index df068f3..34153a2 100644 --- a/tests/integration/test_environment.py +++ b/tests/integration/test_environment.py @@ -15,6 +15,7 @@ from softpack_core.artifacts import Artifacts, app from softpack_core.schemas.environment import ( + BuilderError, CreateEnvironmentSuccess, DeleteEnvironmentSuccess, Environment, @@ -26,7 +27,6 @@ State, UpdateEnvironmentSuccess, WriteArtifactSuccess, - BuilderError, ) from tests.integration.utils import file_in_remote @@ -127,7 +127,9 @@ def test_create_path_invalid_disallowed(httpx_post, testable_env_input): assert isinstance(result, InvalidInputError) -def test_create_cleans_up_after_builder_failure(httpx_post, testable_env_input): +def test_create_cleans_up_after_builder_failure( + httpx_post, testable_env_input +): httpx_post.side_effect = Exception('could not contact builder') result = Environment.create(testable_env_input) assert isinstance(result, BuilderError)