Beispiel #1
0
def test_BazelClient_Run_stdout(workspace: pathlib.Path, tempdir: pathlib.Path):
  """Check stdout of test target."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  assert process.stdout == "Hello, stdout!\n"
Beispiel #2
0
def test_BazelClient_Run_stderr(workspace: pathlib.Path, tempdir: pathlib.Path):
  """Check stderr of test target."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  # Stderr starts with bazel build log.
  print(process.stderr)
  assert "Hello, stderr!\n" in process.stderr
Beispiel #3
0
def test_BazelClient_Run_returncode(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Check returncode of test target."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  assert process.returncode == 0
Beispiel #4
0
def test_BazelClient_Run_process_id(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Check that process ID is set."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  assert process.pid
  assert process.pid != system.PID
Beispiel #5
0
def test_BazeClient_run_missing_target(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Check error for missing target."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(
    alice_pb2.RunRequest(target="//:not_a_target", ledger_id=1,)
  )

  process.join()
  assert process.returncode
Beispiel #6
0
def test_BazelClient_Run_workdir_files(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Check that output files are generated."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  assert (process.workdir / "stdout.txt").is_file()
  assert (process.workdir / "stderr.txt").is_file()
  assert (process.workdir / "returncode.txt").is_file()
Beispiel #7
0
    def __init__(
        self,
        ledger: alice_pb2_grpc.LedgerStub,
        repo: git_repo.PhdRepo,
        output_dir: pathlib.Path,
    ):
        self._ledger = ledger
        self._repo = repo
        self._bazel = bazel.BazelClient(repo.path, output_dir)
        self._processes: typing.Dict[int, bazel.BazelRunProcess] = {}

        self.ledger.RegisterWorkerBee(
            alice_pb2.String(
                string=f"{self.hostname}:{FLAGS.worker_bee_port}"))
Beispiel #8
0
def test_BazelClient_Run_process_isnt_running(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Check that process isn't running after completed."""
  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(alice_pb2.RunRequest(target="//:hello", ledger_id=1,))

  process.join()
  try:
    os.kill(process.pid, 0)
    test.Fail(
      "os.kill() didn't fail, that means the process is still " "running"
    )
  except ProcessLookupError:
    pass
Beispiel #9
0
def test_BazelClient_kill_process(
  workspace: pathlib.Path, tempdir: pathlib.Path
):
  """Test that process can be killed."""
  # Create a binary which will never terminate once launched.
  with open(workspace / "BUILD", "a") as f:
    f.write(
      """
cc_binary(
    name = "nonterminating",
    srcs = ["nonterminating.cc"],
)
"""
    )

  with open(workspace / "nonterminating.cc", "w") as f:
    f.write(
      """
int main() {
  while (1) {}
}
"""
    )

  client = bazel.BazelClient(workspace, tempdir)
  process = client.Run(
    alice_pb2.RunRequest(target="//:nonterminating", ledger_id=1,)
  )

  # Sleep for luck ;-)
  time.sleep(3)

  # Send the non-terminating process a kill signal.
  os.kill(process.pid, signal.SIGTERM)
  process.join()
  try:
    os.kill(process.pid, 0)
    test.Fail(
      "os.kill() didn't fail, that means the process is still " "running"
    )
  except ProcessLookupError:
    pass
Beispiel #10
0
def test_BazelClient_workspace_not_found(tempdir: pathlib.Path):
  """Error is raised if WORKSPACE is not found."""
  with test.Raises(bazel.BazelError):
    (tempdir / "repo").mkdir()
    bazel.BazelClient(tempdir / "repo", tempdir / "work")
Beispiel #11
0
def test_BazelClient_root_dir_not_found(tempdir: pathlib.Path):
  """Error is raised if root dir is not found."""
  with test.Raises(FileNotFoundError):
    bazel.BazelClient(tempdir / "foo", tempdir / "work")