Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pjenvey committed Feb 3, 2024
1 parent f6fd8d7 commit e45901e
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions tests/load/locustfiles/stored.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
from logging import Logger
from typing import Any, TypeAlias

import gevent
import websocket
from args import parse_wait_time
from exceptions import ZeroStatusRequestError
from gevent import Greenlet
from locust import FastHttpUser, events, task
from locust.exception import LocustError
from models import (
Expand All @@ -38,9 +36,6 @@
Message: TypeAlias = HelloMessage | NotificationMessage | RegisterMessage | UnregisterMessage
Record: TypeAlias = HelloRecord | NotificationRecord | RegisterRecord

# Set to 'True' to view the verbose connection information for the web socket
#websocket.enableTrace(False)
#websocket.setdefaulttimeout(5)

logger: Logger = logging.getLogger("StoredNotifAutopushUser")

Expand All @@ -65,8 +60,7 @@ def __init__(self, environment) -> None:
self.register_records: list[RegisterRecord] = []
self.unregister_records: list[RegisterRecord] = []
self.uaid: str = ""
self.ws: WebSocketApp | None = None
self.ws_greenlet: Greenlet | None = None
self.ws: WebSocket = websocket.WebSocket()

def wait_time(self):
return self.environment.autopush_wait_time(self)
Expand All @@ -77,13 +71,9 @@ def on_start(self) -> Any:

def on_stop(self) -> Any:
"""Called when a User stops running."""
if self.ws:
for channel_id in self.channels.keys():
self.send_unregister(self.ws, channel_id)
self.ws.close()
self.ws = None
if self.ws_greenlet:
gevent.kill(self.ws_greenlet)
for channel_id in self.channels.keys():
self.send_unregister(self.ws, channel_id)
self.ws.close()

def on_ws_open(self, ws: WebSocket) -> None:
"""Called when opening a WebSocket.
Expand Down Expand Up @@ -144,7 +134,7 @@ def on_ws_close(
@task(weight=78)
def send_notification(self):
"""Sends a notification to a registered endpoint while connected to Autopush."""
if not self.ws or not self.channels:
if not self.channels:
logger.debug("Task 'send_notification' skipped.")
return

Expand All @@ -154,10 +144,6 @@ def send_notification(self):
@task(weight=1)
def subscribe(self):
"""Subscribes a user to an Autopush channel."""
if not self.ws:
logger.debug("Task 'subscribe' skipped.")
return

if not self.ws.connected:
self.connect_and_hello()
channel_id: str = str(uuid.uuid4())
Expand All @@ -168,7 +154,7 @@ def subscribe(self):
@task(weight=1)
def unsubscribe(self):
"""Unsubscribes a user from an Autopush channel."""
if not self.ws or not self.channels:
if not self.channels:
logger.debug("Task 'unsubscribe' skipped.")
return

Expand Down Expand Up @@ -205,7 +191,7 @@ def connect_and_hello(self) -> None:
for _ in range(len(self.notification_records)):
self.recv_message()

def recv_message(self) -> None:
def recv_message(self):
self.on_ws_message(self.ws, self.ws.recv())

def post_notification(self, endpoint_url: str) -> None:
Expand Down Expand Up @@ -362,7 +348,7 @@ def send_register(self, ws: WebSocket, channel_id: str) -> None:
self.register_records.append(record)
self.send(ws, message_type, data)

def send_unregister(self, ws: WebSocketApp, channel_id: str) -> None:
def send_unregister(self, ws: WebSocket, channel_id: str) -> None:
"""Send an 'unregister' message to Autopush.
Args:
Expand Down

0 comments on commit e45901e

Please sign in to comment.