Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gshuflin committed Jul 9, 2020
1 parent de18cc7 commit fd78926
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/python/pants/engine/internals/scheduler_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import re
from pathlib import Path
from textwrap import dedent

from pants.base.build_environment import get_buildroot
from pants.testutil.pants_run_integration_test import PantsRunIntegrationTest, ensure_daemon
from pants.util.contextutil import temporary_dir

Expand Down Expand Up @@ -34,3 +37,49 @@ def test_graceful_termination(self):
pants_result.stdout_data, "examples/src/python/example/hello/greet:greet\n",
)
self.assertEqual(pants_result.returncode, 42)

def prepare_concurrency_slot_sources(self, tmpdir: str) -> None:
src_root = Path(tmpdir, "src", "python", "project")
src_root.mkdir(parents=True)

(src_root / "fake_test.py").write_text(
dedent(
"""\
import os
def test_fail_printing_slot_env_var():
slot = os.getenv("SLOT")
print(f"Value of slot is {slot}")
#Deliberately fail the test so the SLOT output gets printed
assert 1 == 2
"""
)
)

(src_root / "BUILD").write_text(
dedent(
"""\
python_tests(
name="fake",
sources=["fake_test.py"],
dependencies=[],
)
"""
)
)

def test_concurrency_slot_variable(self) -> None:
build_root = get_buildroot()
with temporary_dir(root_dir=build_root) as tmpdir:
tmpdir_relative = Path(tmpdir).relative_to(build_root)
self.prepare_concurrency_slot_sources(tmpdir)
result = self.run_pants(
[
"--no-dynamic-ui",
"--process-execution-slot-environment-variable=SLOT",
"test",
f"{tmpdir_relative}/src/python/project:fake",
]
)

assert re.search(r"Value of slot is \d+", result.stderr_data)

0 comments on commit fd78926

Please sign in to comment.