-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS-1197] feat: use nextest #16
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
413e78d
refactor: rework tracing config + use tokio
GuillaumeDecMeetsMore 853f555
chore: add comments
GuillaumeDecMeetsMore 2aa997e
Merge branch 'master' into guillaume/refactor/rework-tracing-and-tokio
GuillaumeDecMeetsMore 3e3a7d8
chore: revert tokio changes
GuillaumeDecMeetsMore cc08ebd
feat: use nextest
GuillaumeDecMeetsMore b2e82e9
chore: run the tests on a temporary container
GuillaumeDecMeetsMore a0344a9
Merge branch 'master' into guillaume/feat/use-nextest
GuillaumeDecMeetsMore 2d3af00
chore: add comment
GuillaumeDecMeetsMore 6989ad3
refactor: use ryuk to avoid leaving running containers behind
GuillaumeDecMeetsMore 2c4d7b4
Merge branch 'master' into guillaume/feat/use-nextest
GuillaumeDecMeetsMore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Test group for running some tests serially | ||
[test-groups] | ||
serial-integration = { max-threads = 1 } | ||
|
||
# Tests that contain `serial_` are run serially | ||
[[profile.default.overrides]] | ||
filter = 'test(serial_)' | ||
test-group = 'serial-integration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#! /bin/bash | ||
|
||
# Script to run all the (Rust) tests of the scheduler project | ||
# It launches a temporary PostgreSQL container, runs the migrations, runs the tests and then stops and removes the container | ||
|
||
# Function to clean up the containers | ||
CLEANUP_CALLED=false | ||
cleanup() { | ||
if [ "$CLEANUP_CALLED" = true ]; then | ||
return | ||
fi | ||
echo "Cleaning up..." | ||
CLEANUP_CALLED=true | ||
|
||
if [ -n "$NC_PID" ] && kill -0 $NC_PID 2>/dev/null; then | ||
kill $NC_PID >/dev/null 2>&1 | ||
fi | ||
|
||
if [ "$(docker ps -q -f name=$RANDOM_NAME)" ]; then | ||
docker stop $RANDOM_NAME >/dev/null 2>&1 | ||
fi | ||
|
||
if [ "$(docker ps -q -f name=ryuk)" ]; then | ||
docker stop ryuk >/dev/null 2>&1 | ||
fi | ||
} | ||
|
||
# Set up a trap to call the cleanup function on EXIT, SIGINT, and SIGTERM | ||
trap cleanup EXIT SIGINT SIGTERM | ||
|
||
# Search for a free port to bind the temporary PG container | ||
BASE_PORT=1234 | ||
INCREMENT=1 | ||
|
||
PORT=$BASE_PORT | ||
IS_FREE=$(netstat -taln | grep $PORT) | ||
|
||
while [[ -n "$IS_FREE" ]]; do | ||
PORT=$((PORT + INCREMENT)) | ||
IS_FREE=$(netstat -taln | grep $PORT) | ||
done | ||
|
||
# Generate a random name for the temporary PG container | ||
RANDOM_NAME="pg_test_$(date +%s)" | ||
|
||
LABEL="nittei_testing=true" | ||
|
||
cd scheduler && cargo build --workspace | ||
|
||
# Launch the resource reaper (like testcontainers) | ||
docker run -d --name ryuk --rm -v /var/run/docker.sock:/var/run/docker.sock -e RYUK_VERBOSE=true -e RYUK_PORT=8080 -p 8080:8080 testcontainers/ryuk:0.8.1 >/dev/null 2>&1 | ||
|
||
# Keep the connection open and send the label to Ryuk | ||
TIMEOUT=60 | ||
( | ||
echo "label=${LABEL}" | ||
# Keep the connection open to Ryuk and read the ACK response | ||
while [ $((TIMEOUT--)) -gt 0 ]; do | ||
sleep 1 | ||
done | ||
) | nc localhost 8080 & | ||
>/dev/null 2>&1 | ||
NC_PID=$! | ||
|
||
# Launch a PG container | ||
docker run --rm -d -l ${LABEL} --name $RANDOM_NAME -p $PORT:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=scheduler postgres:13 >/dev/null 2>&1 | ||
|
||
# Set the DATABASE_URL environment variable | ||
export DATABASE_URL="postgres://postgres:postgres@localhost:${PORT}/scheduler" | ||
|
||
# Run the migrations | ||
cd crates/infra && sqlx migrate run && cd ../.. | ||
|
||
# Run the tests | ||
cargo nextest run --workspace && cd .. | ||
|
||
# The cleanup function will be called automatically |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] Could we just use testcontainers for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I forgot to post my comment about this 😓
I wanted to use
testcontainers
, but the problems is that Rust by default doesn't have a concept of global "beforeAll" and "afterAll"nextest
does have the feature forbeforeAll
(as an experimental feature), but from what I understand, it's a "one time thing". So, usingtestcontainers
there or a shell script would mean that the containers would start and be killed before running the tests (because the script/app/context is killed before).(technically, it would work fine for starting the containers. The issue would be on how to garbage collect them)
Note that with NodeJS, I believe it works by keeping a connection opened to the Ryuk container. This is possible because the NodeJS context ("main context") stays alive as long as the tests are running (and the tests are ran inside this context via the use of the
vm
module). Once the tests are finished, the app "exits", Ryuk detects that the connection is closed and therefore it can kill the containers.Here, for Rust, from what I understand, each file of test is like a binary executed independently, so we don't have that "main context" (or it's not accessible from what I searched).
So wrapping everything in a shell script seemed the easiest and less complex 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!