Skip to content

Commit

Permalink
Load environment variables in smoke test, doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
b9r5 committed Nov 19, 2024
1 parent 730146a commit 9ba2159
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Every triggered job is containerized so we don't have to worry too much about se

Instead of testing on GPU MODE directly we can leverage a staging environment called "Discord Cluster Staging". If you need access to this server please ping "Seraphim", however, you can also test the bot on your own server by following the instructions below.

The smoke test script in `tests/discord-bot-smoke-test.py` should be run to verify basic functionality of the cluster bot. For usage information, run with `python tests/discord-bot-smoke-test.py -h`.
The smoke test script in `tests/discord-bot-smoke-test.py` should be run to verify basic functionality of the cluster bot. For usage information, run with `python tests/discord-bot-smoke-test.py -h`. Run it against your own server (see below for instructions).

### How to add the bot to a personal server

Expand Down
25 changes: 14 additions & 11 deletions tests/discord-bot-smoke-test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from dotenv import load_dotenv
import discord
import logging
import os
import argparse
import asyncio
import re
import sys

# Set up logging
logging.basicConfig(
Expand All @@ -13,6 +15,10 @@
)
logger = logging.getLogger(__name__)

# Load environment variables
load_dotenv()
logger.info("Environment variables loaded")

parser = argparse.ArgumentParser(
description='Smoke Test for the Discord Cluster Bot',
epilog=f"""
Expand Down Expand Up @@ -42,16 +48,12 @@
# Flag set to true if the thread tests pass
thread_tests_passed = False

async def test_thread_messages():
async def verify_thread_messages():
"""
Test messages from a Discord thread identified by a message ID.
Args:
client (discord.Client): the Discord client
message_id (int): the ID of the message under which to find thread messsages
Side effect:
- Sets thread_tests_passed to True if all happy path messages are found
Sets thread_tests_passed to True if all happy path messages are found
"""

global thread_tests_passed
Expand All @@ -60,7 +62,7 @@ async def test_thread_messages():
"Found train.py! Starting training process",
"GitHub Action triggered successfully! Run ID:",
"Training completed with status: success",
".*\nLogs.*:",
".*```\nLogs.*:",
"View the full run at:",
]

Expand Down Expand Up @@ -119,7 +121,7 @@ async def test_thread_messages():

@client.event
async def on_ready():
await test_thread_messages()
await verify_thread_messages()

# We could add additional tests that use the client here if needed.

Expand All @@ -142,9 +144,10 @@ async def await_client_tests():
asyncio.run(await_client_tests())

if not thread_tests_passed:
# If other tests are needed, add `... and other_test_passed` above.
# If other tests are needed, add them above
# if (not thread_test_passed) or (not other_test_passed):
logger.warning("One or more tests failed!")
exit(1)
sys.exit(1)
else:
logger.info('All tests passed!')
exit(0)
sys.exit(0)

0 comments on commit 9ba2159

Please sign in to comment.