Example #1
0
    def test_simple_sync(self):
        db2 = DB(":memory:")
        s2 = Syncer(db2, "Syncer2", 0, set([self.s.local_addr()]), db_poll_interval=0.1, connect_interval=0.2)
        self.s.add_address(s2.local_addr())

        self.wait_for_connection(s2)

        with self.db.transaction():
            self.db.update(Object("apa", init={u"test": ValueSet(u"4", t=5)}))
        wait_for(lambda: "test" in db2["apa"])
        with db2.transaction():
            db2.update(Object("apa", init={u"test": ValueSet(u"7")}))
        wait_for(lambda: self.db["apa"]["test"] == ValueSet(u"7"))
Example #2
0
class TestSyncServer:
    def setup(self):
        self.db = DB(":memory:")
        self.s = Syncer(self.db, "Syncer1", 0, db_poll_interval=0.1, connect_interval=0.2)

    def wait_for_connection(self, other):
        wait_for(lambda: str(self.s.name) in other.connections)
        wait_for(lambda: str(other.name) in self.s.connections)

    def connect(self, name="Syncer2"):
        db = DB(":memory:")
        s = concurrent.connect(self.s.local_addr())
        return SyncConnection(db, name, s, None)

    def test_simple_sync(self):
        db2 = DB(":memory:")
        s2 = Syncer(db2, "Syncer2", 0, set([self.s.local_addr()]), db_poll_interval=0.1, connect_interval=0.2)
        self.s.add_address(s2.local_addr())

        self.wait_for_connection(s2)

        with self.db.transaction():
            self.db.update(Object("apa", init={u"test": ValueSet(u"4", t=5)}))
        wait_for(lambda: "test" in db2["apa"])
        with db2.transaction():
            db2.update(Object("apa", init={u"test": ValueSet(u"7")}))
        wait_for(lambda: self.db["apa"]["test"] == ValueSet(u"7"))

    def test_disconnect(self):
        s = self.connect()
        s.handshake()
        self.s.close()
        s.run()

    def test_handshake_timeout(self):
        s = self.connect()
        syncer.HANDSHAKE_TIMEOUT = 0.2
        assert_equal(s.read_msg(), sync_pb2.Hello(name="Syncer1"))
        assert_equal(s.read_msg(), None)