Exemplo n.º 1
0
 def test_can_commit_timeouted(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_timeouted("h7h2v")
     checker.write_ended("2hch4")
Exemplo n.º 2
0
 def test_write_fork2_err(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("j3qq4", "2hch4", 1, "44")
     checker.write_ended("2hch4")
     try:
         checker.write_ended("h7h2v")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "h7h2v:1 -> j3qq4 doesn't lead to the latest observed state: 2hch4:1":
             raise e
Exemplo n.º 3
0
 def test_cant_commit_gced(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("j3qq4", "2hch4", 2, "44")
     checker.write_ended("2hch4")
     try:
         checker.write_ended("h7h2v")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "current head 2hch4:2 doesn't lead to h7h2v and has greater version":
             raise e
Exemplo n.º 4
0
 def test_cant_cancel_comitted(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_ended("2hch4")
     try:
         checker.write_canceled("h7h2v")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "Can't cancel an already applied write: h7h2v":
             raise e
Exemplo n.º 5
0
 def test_cant_commit_canceled(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_canceled("h7h2v")
     try:
         checker.write_ended("2hch4")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "2hch4:2 -> h7h2v doesn't lead to the latest observed state: j3qq4:0":
             raise e
Exemplo n.º 6
0
 def test_write_out_order_ok(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_ended("2hch4")
     checker.write_ended("h7h2v")
Exemplo n.º 7
0
 def test_read_wrong_value_err(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.read_started("pid1")
     try:
         checker.read_ended("pid1", "j3qq4", "43")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "Read value 43 doesn't match written value 42":
             raise e
Exemplo n.º 8
0
 def test_read_phantom_err(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.read_started("pid1")
     try:
         checker.read_ended("pid1", "h7h2v", "42")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "Stale or phantom read h7h2v":
             raise e
Exemplo n.º 9
0
 def test_write_out_order_wrong_version_err(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_started("h7h2v", "2hch4", 1, "44")
     try:
         checker.write_ended("2hch4")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "2hch4:1 -> h7h2v doesn't lead to the pending state: h7h2v:1":
             raise e
Exemplo n.º 10
0
 def test_read_old_after_canceled_ok(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_ended("h7h2v")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_canceled("2hch4")
     checker.read_started("pid1")
     checker.read_ended("pid1", "h7h2v", "43")
Exemplo n.º 11
0
 def test_read_new_after_canceled_err(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_ended("h7h2v")
     checker.write_started("h7h2v", "2hch4", 2, "44")
     checker.write_canceled("2hch4")
     checker.read_started("pid1")
     try:
         checker.read_ended("pid1", "2hch4", "44")
         raise Exception("should be unreachable")
     except Violation as e:
         if e.message != "Stale or phantom read 2hch4":
             raise e
Exemplo n.º 12
0
 def test_read_old_after_timeout(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.write_timeouted("h7h2v")
     checker.read_started("pid1")
     checker.read_ended("pid1", "j3qq4", "42")
Exemplo n.º 13
0
 def test_read_commits_write1(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.read_started("pid1")
     checker.write_started("j3qq4", "h7h2v", 1, "43")
     checker.read_ended("pid1", "h7h2v", "43")
     checker.write_ended("h7h2v")
Exemplo n.º 14
0
 def test_read_ok(self):
     checker = LinearizabilityRegisterChecker()
     checker.init("j3qq4", 0, "42")
     checker.read_started("pid1")
     checker.read_ended("pid1", "j3qq4", "42")
Exemplo n.º 15
0
    def init(self, write_id, key, version, value):
        if key in self.checkers:
            raise Exception(f"Key {key} is already known, use cas to update")

        self.checkers[key] = LinearizabilityRegisterChecker()
        self.checkers[key].init(write_id, version, value)