예제 #1
0
 def test_purge_metadata_error(self):
     with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
         mock_rm.side_effect = OSError(errno.EACCES,
                                       os.strerror(errno.EACCES))
         with self.assertRaises(ProcessManager.MetadataError):
             ProcessMetadataManager.purge_metadata_by_name(self.NAME)
     self.assertGreater(mock_rm.call_count, 0)
예제 #2
0
 def test_readwrite_metadata_by_name(self):
     with temporary_dir() as tmpdir, mock.patch("pants.pantsd.process_manager.get_buildroot", return_value=tmpdir):
         ProcessMetadataManager.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)
         self.assertEqual(ProcessMetadataManager.read_metadata_by_name(self.NAME, self.TEST_KEY), self.TEST_VALUE)
         self.assertEqual(
             ProcessMetadataManager.read_metadata_by_name(self.NAME, self.TEST_KEY, int), self.TEST_VALUE_INT
         )
예제 #3
0
  def test_await_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      ProcessMetadataManager.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)

      self.assertEquals(
        ProcessMetadataManager.await_metadata_by_name(self.NAME, self.TEST_KEY, .1),
        self.TEST_VALUE
      )
예제 #4
0
    def test_await_metadata_by_name(self):
        with temporary_dir() as tmpdir, \
             mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
            ProcessMetadataManager.write_metadata_by_name(
                self.NAME, self.TEST_KEY, self.TEST_VALUE)

            self.assertEquals(
                ProcessMetadataManager.await_metadata_by_name(
                    self.NAME, self.TEST_KEY, .1), self.TEST_VALUE)
예제 #5
0
 def test_get_metadata_dir_by_name(self):
     with mock.patch("pants.pantsd.process_manager.get_buildroot") as mock_buildroot:
         mock_buildroot.return_value = self.BUILDROOT
         self.assertEqual(
             ProcessMetadataManager._get_metadata_dir_by_name(self.NAME),
             os.path.join(self.BUILDROOT, ".pids", self.NAME),
         )
예제 #6
0
 def test_get_metadata_dir_by_name(self):
     with mock.patch('pants.pantsd.process_manager.get_buildroot'
                     ) as mock_buildroot:
         mock_buildroot.return_value = self.BUILDROOT
         self.assertEqual(
             ProcessMetadataManager._get_metadata_dir_by_name(self.NAME),
             os.path.join(self.BUILDROOT, '.pids', self.NAME))
예제 #7
0
 def test_purge_metadata_error(self):
   with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
     mock_rm.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES))
     with self.assertRaises(ProcessManager.MetadataError):
       ProcessMetadataManager.purge_metadata_by_name(self.NAME)
   self.assertGreater(mock_rm.call_count, 0)
예제 #8
0
 def test_purge_metadata(self):
   with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
     ProcessMetadataManager.purge_metadata_by_name(self.NAME)
   self.assertGreater(mock_rm.call_count, 0)
예제 #9
0
 def setUp(self):
     super().setUp()
     self.pmm = ProcessMetadataManager(metadata_base_dir=self.SUBPROCESS_DIR)
예제 #10
0
 def test_wait_for_file_timeout(self):
   with temporary_dir() as td:
     with self.assertRaises(ProcessMetadataManager.Timeout):
       ProcessMetadataManager._wait_for_file(os.path.join(td, 'non_existent_file'), timeout=.1)
예제 #11
0
 def test_wait_for_file(self):
     with temporary_dir() as td:
         test_filename = os.path.join(td, 'test.out')
         safe_file_dump(test_filename, 'test')
         ProcessMetadataManager._wait_for_file(test_filename, timeout=.1)
예제 #12
0
class TestProcessMetadataManager(TestBase):
  NAME = '_test_'
  TEST_KEY = 'TEST'
  TEST_VALUE = '300'
  TEST_VALUE_INT = 300
  BUILDROOT = '/mock_buildroot/'

  def setUp(self):
    super(TestProcessMetadataManager, self).setUp()
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)

  def test_maybe_cast(self):
    self.assertIsNone(self.pmm._maybe_cast(None, int))
    self.assertEqual(self.pmm._maybe_cast('3333', int), 3333)
    self.assertEqual(self.pmm._maybe_cast('ssss', int), 'ssss')

  def test_get_metadata_dir_by_name(self):
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
    self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME, self.BUILDROOT),
                     os.path.join(self.BUILDROOT, self.NAME))

  def test_maybe_init_metadata_dir_by_name(self):
    with mock.patch('pants.pantsd.process_manager.safe_mkdir', **PATCH_OPTS) as mock_mkdir:
      self.pmm._maybe_init_metadata_dir_by_name(self.NAME)
      mock_mkdir.assert_called_once_with(
        self.pmm._get_metadata_dir_by_name(self.NAME, self.subprocess_dir))

  def test_readwrite_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY),
        self.TEST_VALUE
      )
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY, int),
        self.TEST_VALUE_INT
      )

  def test_deadline_until(self):
    with self.assertRaises(self.pmm.Timeout):
      with self.captured_logging(logging.INFO) as captured:
        self.pmm._deadline_until(lambda: False, 'the impossible', timeout=.5, info_interval=.1)
    self.assertTrue(4 <= len(captured.infos()) <= 6,
                    'Expected between 4 and 6 infos, got: {}'.format(captured.infos()))

  def test_wait_for_file(self):
    with temporary_dir() as td:
      test_filename = os.path.join(td, 'test.out')
      safe_file_dump(test_filename, 'test')
      self.pmm._wait_for_file(test_filename, timeout=.1)

  def test_wait_for_file_timeout(self):
    with temporary_dir() as td:
      with self.assertRaises(self.pmm.Timeout):
        self.pmm._wait_for_file(os.path.join(td, 'non_existent_file'), timeout=.1)

  def test_await_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)

      self.assertEquals(
        self.pmm.await_metadata_by_name(self.NAME, self.TEST_KEY, .1),
        self.TEST_VALUE
      )

  def test_purge_metadata(self):
    with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)

  def test_purge_metadata_error(self):
    with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      mock_rm.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES))
      with self.assertRaises(ProcessManager.MetadataError):
        self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)
예제 #13
0
 def _retrieve_pailgun_port(self):
     return ProcessMetadataManager(
         self._process_metadata_dir).read_metadata_by_name(
             'pantsd', 'socket_pailgun', int)
예제 #14
0
 def test_get_metadata_dir_by_name(self):
   self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
   self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME, self.BUILDROOT),
                    os.path.join(self.BUILDROOT, self.NAME))
예제 #15
0
 def test_maybe_cast(self):
     self.assertIsNone(ProcessMetadataManager._maybe_cast(None, int))
     self.assertEqual(ProcessMetadataManager._maybe_cast("3333", int), 3333)
     self.assertEqual(ProcessMetadataManager._maybe_cast("ssss", int), "ssss")
예제 #16
0
 def test_maybe_init_metadata_dir_by_name(self):
     with mock.patch('pants.pantsd.process_manager.safe_mkdir',
                     **PATCH_OPTS) as mock_mkdir:
         ProcessMetadataManager._maybe_init_metadata_dir_by_name(self.NAME)
         mock_mkdir.assert_called_once_with(
             ProcessMetadataManager._get_metadata_dir_by_name(self.NAME))
예제 #17
0
 def test_maybe_cast(self):
     self.assertIsNone(ProcessMetadataManager._maybe_cast(None, int))
     self.assertEqual(ProcessMetadataManager._maybe_cast('3333', int), 3333)
     self.assertEqual(ProcessMetadataManager._maybe_cast('ssss', int),
                      'ssss')
예제 #18
0
 def test_deadline_until(self):
     with self.assertRaises(ProcessMetadataManager.Timeout):
         ProcessMetadataManager._deadline_until(lambda: False, timeout=.1)
예제 #19
0
 def test_purge_metadata(self):
     with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
         ProcessMetadataManager.purge_metadata_by_name(self.NAME)
     self.assertGreater(mock_rm.call_count, 0)
예제 #20
0
 def test_maybe_cast(self):
   self.assertIsNone(ProcessMetadataManager._maybe_cast(None, int))
   self.assertEqual(ProcessMetadataManager._maybe_cast('3333', int), 3333)
   self.assertEqual(ProcessMetadataManager._maybe_cast('ssss', int), 'ssss')
예제 #21
0
 def setUp(self):
   super(TestProcessMetadataManager, self).setUp()
   self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)
예제 #22
0
 def test_maybe_init_metadata_dir_by_name(self):
   with mock.patch('pants.pantsd.process_manager.safe_mkdir', **PATCH_OPTS) as mock_mkdir:
     ProcessMetadataManager._maybe_init_metadata_dir_by_name(self.NAME)
     mock_mkdir.assert_called_once_with(
       ProcessMetadataManager._get_metadata_dir_by_name(self.NAME))
예제 #23
0
class TestProcessMetadataManager(BaseTest):
    NAME = "_test_"
    TEST_KEY = "TEST"
    TEST_VALUE = "300"
    TEST_VALUE_INT = 300
    BUILDROOT = "/mock_buildroot/"

    def setUp(self):
        super(TestProcessMetadataManager, self).setUp()
        self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)

    def test_maybe_cast(self):
        self.assertIsNone(self.pmm._maybe_cast(None, int))
        self.assertEqual(self.pmm._maybe_cast("3333", int), 3333)
        self.assertEqual(self.pmm._maybe_cast("ssss", int), "ssss")

    def test_get_metadata_dir_by_name(self):
        self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
        self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME), os.path.join(self.BUILDROOT, self.NAME))

    def test_maybe_init_metadata_dir_by_name(self):
        with mock.patch("pants.pantsd.process_manager.safe_mkdir", **PATCH_OPTS) as mock_mkdir:
            self.pmm._maybe_init_metadata_dir_by_name(self.NAME)
            mock_mkdir.assert_called_once_with(self.pmm._get_metadata_dir_by_name(self.NAME))

    def test_readwrite_metadata_by_name(self):
        with temporary_dir() as tmpdir, mock.patch("pants.pantsd.process_manager.get_buildroot", return_value=tmpdir):
            self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)
            self.assertEqual(self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY), self.TEST_VALUE)
            self.assertEqual(self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY, int), self.TEST_VALUE_INT)

    def test_deadline_until(self):
        with self.assertRaises(self.pmm.Timeout):
            self.pmm._deadline_until(lambda: False, timeout=0.1)

    def test_wait_for_file(self):
        with temporary_dir() as td:
            test_filename = os.path.join(td, "test.out")
            safe_file_dump(test_filename, "test")
            self.pmm._wait_for_file(test_filename, timeout=0.1)

    def test_wait_for_file_timeout(self):
        with temporary_dir() as td:
            with self.assertRaises(self.pmm.Timeout):
                self.pmm._wait_for_file(os.path.join(td, "non_existent_file"), timeout=0.1)

    def test_await_metadata_by_name(self):
        with temporary_dir() as tmpdir, mock.patch("pants.pantsd.process_manager.get_buildroot", return_value=tmpdir):
            self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)

            self.assertEquals(self.pmm.await_metadata_by_name(self.NAME, self.TEST_KEY, 0.1), self.TEST_VALUE)

    def test_purge_metadata(self):
        with mock.patch("pants.pantsd.process_manager.rm_rf") as mock_rm:
            self.pmm.purge_metadata_by_name(self.NAME)
        self.assertGreater(mock_rm.call_count, 0)

    def test_purge_metadata_error(self):
        with mock.patch("pants.pantsd.process_manager.rm_rf") as mock_rm:
            mock_rm.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES))
            with self.assertRaises(ProcessManager.MetadataError):
                self.pmm.purge_metadata_by_name(self.NAME)
        self.assertGreater(mock_rm.call_count, 0)
예제 #24
0
class TestProcessMetadataManager(TestBase):
    NAME = "_test_"
    TEST_KEY = "TEST"
    TEST_VALUE = "300"
    TEST_VALUE_INT = 300
    BUILDROOT = "/mock_buildroot/"

    def setUp(self):
        super().setUp()
        self.pmm = ProcessMetadataManager(
            metadata_base_dir=self.subprocess_dir)

    def test_maybe_cast(self):
        self.assertIsNone(self.pmm._maybe_cast(None, int))
        self.assertEqual(self.pmm._maybe_cast("3333", int), 3333)
        self.assertEqual(self.pmm._maybe_cast("ssss", int), "ssss")

    def test_get_metadata_dir_by_name(self):
        self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
        self.assertEqual(
            self.pmm._get_metadata_dir_by_name(self.NAME, self.BUILDROOT),
            os.path.join(self.BUILDROOT, self.NAME),
        )

    def test_maybe_init_metadata_dir_by_name(self):
        with unittest.mock.patch("pants.pantsd.process_manager.safe_mkdir",
                                 **PATCH_OPTS) as mock_mkdir:
            self.pmm._maybe_init_metadata_dir_by_name(self.NAME)
            mock_mkdir.assert_called_once_with(
                self.pmm._get_metadata_dir_by_name(self.NAME,
                                                   self.subprocess_dir))

    def test_readwrite_metadata_by_name(self):
        with temporary_dir() as tmpdir, unittest.mock.patch(
                "pants.pantsd.process_manager.get_buildroot",
                return_value=tmpdir):
            self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY,
                                            self.TEST_VALUE)
            self.assertEqual(
                self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY),
                self.TEST_VALUE)
            self.assertEqual(
                self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY, int),
                self.TEST_VALUE_INT)

    @pytest.mark.skip(
        reason="flaky: https://github.com/pantsbuild/pants/issues/6836")
    def test_deadline_until(self):
        with self.assertRaises(ProcessMetadataManager.Timeout):
            with self.captured_logging(logging.INFO) as captured:
                self.pmm._deadline_until(lambda: False,
                                         "the impossible",
                                         timeout=0.5,
                                         info_interval=0.1)
        self.assertTrue(
            4 <= len(captured.infos()) <= 6,
            f"Expected between 4 and 6 infos, got: {captured.infos()}",
        )

    def test_wait_for_file(self):
        with temporary_dir() as td:
            test_filename = os.path.join(td, "test.out")
            safe_file_dump(test_filename, "test")
            self.pmm._wait_for_file(test_filename,
                                    "file to be created",
                                    "file was created",
                                    timeout=0.1)

    def test_wait_for_file_timeout(self):
        with temporary_dir() as td:
            with self.assertRaises(ProcessMetadataManager.Timeout):
                self.pmm._wait_for_file(
                    os.path.join(td, "non_existent_file"),
                    "file to be created",
                    "file was created",
                    timeout=0.1,
                )

    def test_await_metadata_by_name(self):
        with temporary_dir() as tmpdir, unittest.mock.patch(
                "pants.pantsd.process_manager.get_buildroot",
                return_value=tmpdir):
            self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY,
                                            self.TEST_VALUE)

            self.assertEqual(
                self.pmm.await_metadata_by_name(self.NAME, self.TEST_KEY,
                                                "metadata to be created",
                                                "metadata was created", 0.1),
                self.TEST_VALUE,
            )

    def test_purge_metadata(self):
        with unittest.mock.patch(
                "pants.pantsd.process_manager.rm_rf") as mock_rm:
            self.pmm.purge_metadata_by_name(self.NAME)
        self.assertGreater(mock_rm.call_count, 0)

    def test_purge_metadata_error(self):
        with unittest.mock.patch(
                "pants.pantsd.process_manager.rm_rf") as mock_rm:
            mock_rm.side_effect = OSError(errno.EACCES,
                                          os.strerror(errno.EACCES))
            with self.assertRaises(ProcessMetadataManager.MetadataError):
                self.pmm.purge_metadata_by_name(self.NAME)
        self.assertGreater(mock_rm.call_count, 0)
예제 #25
0
 def test_wait_for_file(self):
   with temporary_dir() as td:
     test_filename = os.path.join(td, 'test.out')
     safe_file_dump(test_filename, 'test')
     ProcessMetadataManager._wait_for_file(test_filename, timeout=.1)
예제 #26
0
 def setUp(self):
   super(TestProcessMetadataManager, self).setUp()
   self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)
예제 #27
0
 def test_wait_for_file_timeout(self):
     with temporary_dir() as td:
         with self.assertRaises(ProcessMetadataManager.Timeout):
             ProcessMetadataManager._wait_for_file(os.path.join(
                 td, 'non_existent_file'),
                                                   timeout=.1)
예제 #28
0
class TestProcessMetadataManager(BaseTest):
  NAME = '_test_'
  TEST_KEY = 'TEST'
  TEST_VALUE = '300'
  TEST_VALUE_INT = 300
  BUILDROOT = '/mock_buildroot/'

  def setUp(self):
    super(TestProcessMetadataManager, self).setUp()
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)

  def test_maybe_cast(self):
    self.assertIsNone(self.pmm._maybe_cast(None, int))
    self.assertEqual(self.pmm._maybe_cast('3333', int), 3333)
    self.assertEqual(self.pmm._maybe_cast('ssss', int), 'ssss')

  def test_get_metadata_dir_by_name(self):
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
    self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME),
                     os.path.join(self.BUILDROOT, self.NAME))

  def test_maybe_init_metadata_dir_by_name(self):
    with mock.patch('pants.pantsd.process_manager.safe_mkdir', **PATCH_OPTS) as mock_mkdir:
      self.pmm._maybe_init_metadata_dir_by_name(self.NAME)
      mock_mkdir.assert_called_once_with(
        self.pmm._get_metadata_dir_by_name(self.NAME))

  def test_readwrite_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY),
        self.TEST_VALUE
      )
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY, int),
        self.TEST_VALUE_INT
      )

  def test_deadline_until(self):
    with self.assertRaises(self.pmm.Timeout):
      self.pmm._deadline_until(lambda: False, timeout=.1)

  def test_wait_for_file(self):
    with temporary_dir() as td:
      test_filename = os.path.join(td, 'test.out')
      safe_file_dump(test_filename, 'test')
      self.pmm._wait_for_file(test_filename, timeout=.1)

  def test_wait_for_file_timeout(self):
    with temporary_dir() as td:
      with self.assertRaises(self.pmm.Timeout):
        self.pmm._wait_for_file(os.path.join(td, 'non_existent_file'), timeout=.1)

  def test_await_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)

      self.assertEquals(
        self.pmm.await_metadata_by_name(self.NAME, self.TEST_KEY, .1),
        self.TEST_VALUE
      )

  def test_purge_metadata(self):
    with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)

  def test_purge_metadata_error(self):
    with mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      mock_rm.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES))
      with self.assertRaises(ProcessManager.MetadataError):
        self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)
예제 #29
0
 def test_deadline_until(self):
   with self.assertRaises(ProcessMetadataManager.Timeout):
     ProcessMetadataManager._deadline_until(lambda: False, timeout=.1)
예제 #30
0
 def test_get_metadata_dir_by_name(self):
   self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
   self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME),
                    os.path.join(self.BUILDROOT, self.NAME))
예제 #31
0
class TestProcessMetadataManager(TestBase):
  NAME = '_test_'
  TEST_KEY = 'TEST'
  TEST_VALUE = '300'
  TEST_VALUE_INT = 300
  BUILDROOT = '/mock_buildroot/'

  def setUp(self):
    super().setUp()
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.subprocess_dir)

  def test_maybe_cast(self):
    self.assertIsNone(self.pmm._maybe_cast(None, int))
    self.assertEqual(self.pmm._maybe_cast('3333', int), 3333)
    self.assertEqual(self.pmm._maybe_cast('ssss', int), 'ssss')

  def test_get_metadata_dir_by_name(self):
    self.pmm = ProcessMetadataManager(metadata_base_dir=self.BUILDROOT)
    self.assertEqual(self.pmm._get_metadata_dir_by_name(self.NAME, self.BUILDROOT),
                     os.path.join(self.BUILDROOT, self.NAME))

  def test_maybe_init_metadata_dir_by_name(self):
    with unittest.mock.patch('pants.pantsd.process_manager.safe_mkdir', **PATCH_OPTS) as mock_mkdir:
      self.pmm._maybe_init_metadata_dir_by_name(self.NAME)
      mock_mkdir.assert_called_once_with(
        self.pmm._get_metadata_dir_by_name(self.NAME, self.subprocess_dir))

  def test_readwrite_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         unittest.mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY),
        self.TEST_VALUE
      )
      self.assertEqual(
        self.pmm.read_metadata_by_name(self.NAME, self.TEST_KEY, int),
        self.TEST_VALUE_INT
      )

  @pytest.mark.flaky(retries=1)  # https://github.com/pantsbuild/pants/issues/6836
  def test_deadline_until(self):
    with self.assertRaises(ProcessMetadataManager.Timeout):
      with self.captured_logging(logging.INFO) as captured:
        self.pmm._deadline_until(lambda: False, 'the impossible', timeout=.5, info_interval=.1)
    self.assertTrue(4 <= len(captured.infos()) <= 6,
                    f'Expected between 4 and 6 infos, got: {captured.infos()}')

  def test_wait_for_file(self):
    with temporary_dir() as td:
      test_filename = os.path.join(td, 'test.out')
      safe_file_dump(test_filename, 'test')
      self.pmm._wait_for_file(test_filename, timeout=.1)

  def test_wait_for_file_timeout(self):
    with temporary_dir() as td:
      with self.assertRaises(ProcessMetadataManager.Timeout):
        self.pmm._wait_for_file(os.path.join(td, 'non_existent_file'), timeout=.1)

  def test_await_metadata_by_name(self):
    with temporary_dir() as tmpdir, \
         unittest.mock.patch('pants.pantsd.process_manager.get_buildroot', return_value=tmpdir):
      self.pmm.write_metadata_by_name(self.NAME, self.TEST_KEY, self.TEST_VALUE)

      self.assertEqual(
        self.pmm.await_metadata_by_name(self.NAME, self.TEST_KEY, .1),
        self.TEST_VALUE
      )

  def test_purge_metadata(self):
    with unittest.mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)

  def test_purge_metadata_error(self):
    with unittest.mock.patch('pants.pantsd.process_manager.rm_rf') as mock_rm:
      mock_rm.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES))
      with self.assertRaises(ProcessMetadataManager.MetadataError):
        self.pmm.purge_metadata_by_name(self.NAME)
    self.assertGreater(mock_rm.call_count, 0)