Beispiel #1
0
 def test_release_nonodeerror(self):
     """
     release_eff deletes child stored in self._node and sets it to None
     if delete raises NoNodeError
     """
     self.lock._node = "/testlock/prefix0000000001"
     seq = [
         (DeleteNode(path=self.lock._node, version=-1),
          conste(NoNodeError()))]
     self.assertIsNone(perform_sequence(seq, self.lock.release_eff()))
     self.assertIsNone(self.lock._node)
Beispiel #2
0
 def test_acquire_other_error(self):
     """
     If acquire_eff internally raises any error then it tries to delete
     child node before returning.
     """
     seq = [
         (Constant(None), noop),
         (zk.CreateNode("/testlock"), const("/testlock")),
         (Func(uuid.uuid4), const("prefix")),
         (zk.CreateNode(
             "/testlock/prefix", value="id",
             ephemeral=True, sequence=True),
          const("/testlock/prefix0000000001")),
         (GetChildren("/testlock"), conste(SessionExpiredError())),
         (DeleteNode(path="/testlock/prefix0000000001", version=-1),
          conste(SessionExpiredError()))
     ]
     self.assertRaises(
         SessionExpiredError, perform_sequence, seq,
         self.lock.acquire_eff(True, 0.3))
Beispiel #3
0
 def test_setup_err(self):
     """
     ``self.s.setup()`` will log any error and return success
     """
     self.s.dispatcher = SequenceDispatcher(
         [(("ggtc", "cf"), conste(ValueError("h")))])
     d = self.s.setup()
     self.successResultOf(d)
     self.log.err.assert_called_once_with(
         CheckFailure(ValueError), "selfheal-setup-err",
         otter_service="selfheal")
Beispiel #4
0
 def test_release_no_node_reset(self):
     """
     If release_eff fails to delete child node, it will not set self._node
     to None
     """
     node = self.lock._node = "/testlock/prefix0000000001"
     seq = [(DeleteNode(path=self.lock._node, version=-1),
             conste(SessionExpiredError()))]
     self.assertRaises(
         SessionExpiredError, perform_sequence, seq,
         self.lock.release_eff())
     self.assertIs(self.lock._node, node)
Beispiel #5
0
 def test_acquire_success(self):
     """
     acquire_eff creates child and gets lock as it is the smallest one
     """
     seq = [
         (Constant(None), noop),
         (zk.CreateNode("/testlock"), conste(NodeExistsError())),
         (Func(uuid.uuid4), const("prefix")),
         (zk.CreateNode(
             "/testlock/prefix", value="id",
             ephemeral=True, sequence=True),
          const("/testlock/prefix0000000000")),
         (GetChildren("/testlock"), const(["prefix0000000000"]))
     ]
     self.assertTrue(
         perform_sequence(seq, self.lock.acquire_eff(False, None)))
Beispiel #6
0
 def test_acquire_delete_child(self):
     """
     acquire_eff deletes existing child if it exists
     """
     self.lock._node = "/testlock/prefix000000002"
     seq = [
         (DeleteNode(path="/testlock/prefix000000002", version=-1), noop),
         (zk.CreateNode("/testlock"), conste(NodeExistsError())),
         (Func(uuid.uuid4), const("prefix")),
         (zk.CreateNode(
             "/testlock/prefix", value="id",
             ephemeral=True, sequence=True),
          const("/testlock/prefix0000000000")),
         (GetChildren("/testlock"), const(["prefix0000000000"]))
     ]
     self.assertTrue(
         perform_sequence(seq, self.lock.acquire_eff(False, None)))