def test_no_reconnect(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .build()

        _lock = threading.Lock()

        _lock.acquire(timeout=10)

        connection.on_open(lambda: _lock.release())

        connection.on("ReceiveMessage", lambda _: _lock.release())

        connection.start()

        self.assertTrue(_lock.acquire(timeout=10))  # Released on ReOpen

        connection.send("DisconnectMe", [])

        self.assertTrue(_lock.acquire(timeout=10))

        time.sleep(10)

        self.assertRaises(HubConnectionError,
                          lambda: connection.send("DisconnectMe", []))

        connection.stop()
        del _lock
Esempio n. 2
0
 def test_enable_trace(self):
     hub = HubConnectionBuilder()\
         .with_url(self.server_url, options={"verify_ssl":False})\
         .configure_logging(logging.WARNING, socket_trace=True)\
         .with_automatic_reconnect({
             "type": "raw",
             "keep_alive_interval": 10,
             "reconnect_interval": 5,
             "max_attempts": 5
         })\
         .build()
     hub.on_open(self.on_open)
     hub.on_close(self.on_close)
     hub.start()
     self.assertTrue(websocket.isEnabledForDebug())
     websocket.enableTrace(False)
     hub.stop()
    def test_reconnect_interval_config(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .with_automatic_reconnect({
                "type": "interval",
                "intervals": [1, 2, 4, 45, 6, 7, 8, 9, 10]
            })\
            .build()
        _lock = threading.Lock()
        connection.on_open(lambda: _lock.release())
        connection.on_close(lambda: _lock.release())

        self.assertTrue(_lock.acquire(timeout=10))

        connection.start()

        self.assertTrue(_lock.acquire(timeout=10))

        connection.stop()

        self.assertTrue(_lock.acquire(timeout=10))

        del _lock
Esempio n. 4
0
    def test_start(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .build()
        
        _lock = threading.Lock()
        self.assertTrue(_lock.acquire(timeout=30))
        

        connection.on_open(lambda: _lock.release())
        connection.on_close(lambda: _lock.release())
        
        result = connection.start()

        self.assertTrue(result)
        
        self.assertTrue(_lock.acquire(timeout=30))  # Released on open
        
        result = connection.start()

        self.assertFalse(result)

        connection.stop()
    .with_url(server_url)\
    .configure_logging(logging.DEBUG)\
    .build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: reconnect)


def reconnect():
    print("connection closed")
    time.sleep(20)
    print("try reconnect")
    hub_connection.start()


hub_connection.on("ReceiveMessage", print)
hub_connection.start()
message = None

# Do login

while message != "exit()":
    message = input(">> ")
    if message is not None and message != "" and message != "exit()":
        hub_connection.send("SendMessage", [username, message])

hub_connection.stop()

sys.exit(0)