Skip to content

Commit e2cdcd2

Browse files
jdetterCentril
andauthored
Smoketests run in parallel (#49)
* Working on improving commands that use identities * Fix lints * Reverted file that shouldn't have changed * Found and fixed all other todos * Addressed more CLI TODOs * Fixes for formatting issues * Set names of identities * Set name of identities + clippy * Small fix * Added the start of a doc comment, switching over to another PR * Fixed tests that needed to be updated * Addressed more feedback and fixed several clippy issues * Small fix * Apply suggestions from code review Co-authored-by: Mazdak Farrokhzad <[email protected]> Signed-off-by: John Detter <[email protected]> * Added more doc comments * Addressing more feedback * Fixed really old bug in SpacetimeDB * Tests to verify new functionality * Fix clippy lints * Email during identity creation is optional * Some work * Getting smoketests working on mac * All tests are passing except known failing tests * Working on parallel smoketests * Fixed some bugs in saving configs that was preventing this from working * Fixes required for parallel tests * Tests are working in parallel * Pruned changes * retab * re-retab * retab the lib file * Cargo profile for building more quickly * I have to rebase on another PR * smoketest fixes * create_project and reset_project are now the same thing, removed create_project * More fixes * Removed print statement * Small fix * Another fix * Tons of improvements to the smoketests * Have to rebase on master * Small fixes * More progress * Finally working correctly! * Apparently we're missing this * Enable command output * Listing installed targets * Clean before building * What is going on * Something super wonky going on * Another test * Skip building containers for now * Small fix * Test using cargo instead * Changed workflow a bit * CI is stuck * Small fix * Another fix * Try cargo run instead of building spacetime CLI * Removed workflow step * Fixing all of the tests * Identity test * Tests should finally be working * Enable debug * Remove spacetime from path * Another try * Logic fix * Another fix * Another fix * Working now? * Another fix * Finally working again * Adding github containers back in * CI fix * Use SpacetimeDB Large Runner * Updated test to get more output * Changed 0ms to 10ms to improve parallel test stability * Removed unused logs Signed-off-by: John Detter <[email protected]> * Removed unnecessary reset_project * Removed reset_config where its not needed * Reset template --------- Signed-off-by: John Detter <[email protected]> Co-authored-by: Boppy <[email protected]> Co-authored-by: Mazdak Farrokhzad <[email protected]>
1 parent 31c545d commit e2cdcd2

36 files changed

+299
-187
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
name: Smoketests
1212
runs-on: spacetimedb-runner
1313
steps:
14-
- uses: actions/checkout@v3
15-
14+
- name: Checkout sources
15+
uses: actions/checkout@v3
1616
- name: Start containers
1717
run: docker compose up -d
1818
- name: Run smoketests
19-
run: test/run-smoke-tests.sh -x bitcraftmini-pretest
19+
run: test/run-smoke-tests.sh --parallel -x bitcraftmini-pretest
2020
- name: Stop containers
2121
if: always()
2222
run: docker compose down

crates/cli/src/config.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ impl Config {
141141
config_filename
142142
}
143143

144-
fn load_raw(config_dir: PathBuf) -> RawConfig {
145-
if let Some(config_path) = std::env::var_os("SPACETIME_CONFIG_FILE") {
146-
return Self::load_from_file(config_path.as_ref());
144+
fn load_raw(config_dir: PathBuf, is_project: bool) -> RawConfig {
145+
// If a config file overload has been specified, use that instead
146+
if !is_project {
147+
if let Some(config_path) = std::env::var_os("SPACETIME_CONFIG_FILE") {
148+
return Self::load_from_file(config_path.as_ref());
149+
}
147150
}
148151
if !config_dir.exists() {
149152
fs::create_dir_all(&config_dir).unwrap();
@@ -174,7 +177,7 @@ impl Config {
174177

175178
pub fn load() -> Self {
176179
let home_dir = dirs::home_dir().unwrap();
177-
let mut home_config = Self::load_raw(home_dir.join(HOME_CONFIG_DIR));
180+
let mut home_config = Self::load_raw(home_dir.join(HOME_CONFIG_DIR), false);
178181

179182
// Ensure there is always an identity config. Simplifies other code.
180183
home_config.identity_configs.get_or_insert(vec![]);
@@ -184,7 +187,7 @@ impl Config {
184187
// search parent directories above the current directory to find
185188
// spacetime.toml files like a .gitignore file
186189
let cur_dir = std::env::current_dir().expect("No current working directory!");
187-
let cur_config = Self::load_raw(cur_dir);
190+
let cur_config = Self::load_raw(cur_dir, true);
188191

189192
Self {
190193
home: home_config,
@@ -193,15 +196,19 @@ impl Config {
193196
}
194197

195198
pub fn save(&self) {
196-
let home_dir = dirs::home_dir().unwrap();
197-
let config_dir = home_dir.join(HOME_CONFIG_DIR);
198-
if !config_dir.exists() {
199-
fs::create_dir_all(&config_dir).unwrap();
200-
}
199+
let config_path = if let Some(config_path) = std::env::var_os("SPACETIME_CONFIG_FILE") {
200+
PathBuf::from(&config_path)
201+
} else {
202+
let home_dir = dirs::home_dir().unwrap();
203+
let config_dir = home_dir.join(HOME_CONFIG_DIR);
204+
if !config_dir.exists() {
205+
fs::create_dir_all(&config_dir).unwrap();
206+
}
201207

202-
let config_filename = Self::find_config_filename(&config_dir).unwrap_or(CONFIG_FILENAME);
208+
let config_filename = Self::find_config_filename(&config_dir).unwrap_or(CONFIG_FILENAME);
209+
config_dir.join(config_filename)
210+
};
203211

204-
let config_path = config_dir.join(config_filename);
205212
let mut file = fs::OpenOptions::new()
206213
.create(true)
207214
.write(true)

crates/cli/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct InitDefaultResult {
110110

111111
pub async fn init_default(config: &mut Config, nickname: Option<String>) -> Result<InitDefaultResult, anyhow::Error> {
112112
if config.name_exists(nickname.as_ref().unwrap_or(&"".to_string())) {
113-
return Err(anyhow::anyhow!("An identity with that name already exists."));
113+
return Err(anyhow::anyhow!("A default identity already exists."));
114114
}
115115

116116
let client = reqwest::Client::new();

docker-compose-release.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,5 @@ services:
3131
core:
3232
soft: -1
3333
hard: -1
34-
35-
prometheus:
36-
build:
37-
context: ./packages/prometheus
38-
ports:
39-
- "9090:9090"
40-
volumes:
41-
- ./packages/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
42-
43-
grafana:
44-
build:
45-
context: ./packages/grafana
46-
ports:
47-
- "3001:3000"
4834
volumes:
4935
key_files:

test/lib.include

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
# Runs a test with the assumption that it will return a zero result code
34
run_test() {
45
set +e
56
"$@" > "$TEST_OUT" 2>&1
@@ -9,6 +10,7 @@ run_test() {
910
return "$RESULT"
1011
}
1112

13+
# Runs a test with the assumption that it will return a non-zero result code
1214
run_fail_test() {
1315
if "$@" > "$TEST_OUT" 2>&1 ; then
1416
cat "$TEST_OUT"
@@ -18,39 +20,19 @@ run_fail_test() {
1820
return 0
1921
}
2022

23+
# This resets the spacetime config for a new test run
2124
reset_config() {
22-
RETURN_DIR=$PWD
23-
cd "$SPACETIME_HOME" || exit 1
24-
cp "./test/config.toml" "$HOME/.spacetime/config.toml"
25-
cd "$RETURN_DIR" || exit 1
25+
SPACETIME_CONFIG_FILE="$(mktemp)"
26+
export SPACETIME_CONFIG_FILE
27+
cp "$RESET_SPACETIME_CONFIG" "$SPACETIME_CONFIG_FILE"
2628
}
2729

2830
# This deletes the project from the previous test run
2931
reset_project() {
30-
RETURN_DIR=$PWD
31-
if [ -d "$PROJECT_PATH" ] ; then
32-
rm -rf "$PROJECT_PATH"
33-
fi
34-
35-
cd "$RETURN_DIR" || exit 1
36-
}
37-
38-
# This creates a new spacetime project that is completely dependent on the local repository.
39-
create_project() {
40-
reset_project
41-
run_test cargo run init --lang=rust "$PROJECT_PATH"
42-
# We have to force using the local spacetimedb_bindings otherwise we will download them from crates.io
43-
if [[ "$OSTYPE" == "darwin"* ]]; then
44-
sed -i '' "s@.*spacetimedb.*=.*@spacetimedb = { path = \"${SPACETIME_DIR}/crates/bindings\" }@g" "${PROJECT_PATH}/Cargo.toml"
45-
elif [[ "$OSTYPE" == "msys"* ]]; then
46-
# Running in git bash; do horrible path conversion; yes we do need all of those
47-
WINPATH="$(cygpath -w "${SPACETIME_DIR}/crates/bindings" | sed 's/\\/\\\\\\\\/g')"
48-
sed -i "s@.*spacetimedb.*=.*@spacetimedb = { path = \"${WINPATH}\" }@g" "${PROJECT_PATH}/Cargo.toml"
49-
else
50-
sed -i "s@.*spacetimedb.*=.*@spacetimedb = { path = \"${SPACETIME_DIR}/crates/bindings\" }@g" "${PROJECT_PATH}/Cargo.toml"
51-
fi
52-
53-
32+
PROJECT_PATH="$(mktemp -d)"
33+
rmdir "$PROJECT_PATH"
34+
cp -rp "$RESET_PROJECT_PATH" "$PROJECT_PATH"
35+
export PROJECT_PATH
5436
}
5537

5638
random_string() {
@@ -65,7 +47,7 @@ spacetime_publish() {
6547
RETURN_DIR=$PWD
6648
cd "$SPACETIME_DIR"
6749
set +e
68-
run_test cargo run publish "$@"
50+
run_test spacetime publish "$@"
6951
RESULT_CODE=$?
7052
cd "$RETURN_DIR" || exit 1
7153
set -e
@@ -74,10 +56,17 @@ spacetime_publish() {
7456

7557
fsed() {
7658
if [[ "$OSTYPE" == "darwin"* ]]; then
77-
sed -i.sed_bak "$@"
78-
rm -f rm *.sed_bak
59+
sed -i.sed_bak "$@"
60+
rm -f rm *.sed_bak
7961
else
80-
sed -i "$@"
62+
sed -i "$@"
8163
fi
8264
}
8365

66+
restart_docker() {
67+
docker-compose stop node
68+
docker-compose start node
69+
sleep 10
70+
}
71+
72+
# vim: noexpandtab tabstop=4 shiftwidth=4

0 commit comments

Comments
 (0)