Skip to content

Commit 3d3d117

Browse files
Enable restart tests (#35)
* Fixes the restart problem (i.e. rebuilding the datastore from the message log) * Remove logging * Enable restart tests * Fixed small issues with tests * Fixed restart-repeating-reducer test probably --------- Co-authored-by: Tyler Cloutier <[email protected]> Co-authored-by: Boppy <[email protected]>
1 parent f54e0a7 commit 3d3d117

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Start containers
1717
run: docker compose up -d
1818
- name: Run smoketests
19-
run: test/run-smoke-tests.sh -x bitcraftmini-pretest zz_docker-restart-repeating-reducer zz_docker-restart-module zz_docker-restart-sql
19+
run: test/run-smoke-tests.sh -x bitcraftmini-pretest
2020
- name: Stop containers
2121
if: always()
2222
run: docker compose down

crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,12 @@ impl Inner {
13271327
col_id: &ColId,
13281328
value: &'a AlgebraicValue,
13291329
) -> super::Result<IterByColEq> {
1330-
let tx_state = self.tx_state.as_ref().unwrap();
1331-
if let Some(inserted_rows) = tx_state.index_seek(table_id, col_id, value) {
1330+
if let Some(inserted_rows) = self
1331+
.tx_state
1332+
.as_ref()
1333+
.and_then(|tx_state| tx_state.index_seek(table_id, col_id, value))
1334+
{
1335+
let tx_state = self.tx_state.as_ref().unwrap();
13321336
Ok(IterByColEq::Index(IndexIterByColEq {
13331337
value,
13341338
col_id: *col_id,

crates/core/src/host/host_controller.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ impl HostController {
175175
Ok(module_host)
176176
}
177177

178+
/// NOTE: Currently repeating reducers are only restarted when the [ModuleHost] is spawned.
179+
/// That means that if SpacetimeDB is restarted, repeating reducers will not be restarted unless
180+
/// there is a trigger that causes the [ModuleHost] to be spawned (e.g. a reducer is run).
181+
///
182+
/// TODO(cloutiertyler): We need to determine what the correct behavior should be. In my mind,
183+
/// the repeating reducers for all [ModuleHost]s should be rescheduled on startup, with the overarching
184+
/// theory that SpacetimeDB should make a best effort to be as invisible as possible and not
185+
/// impact the logic of applications. The idea being that if SpacetimeDB is a distributed operating
186+
/// system, the applications will expect to be called when they are scheduled to be called regardless
187+
/// of whether the OS has been restarted.
178188
pub async fn spawn_module_host(&self, module_host_context: ModuleHostContext) -> Result<ModuleHost, anyhow::Error> {
179189
let key = module_host_context.dbic.database_instance_id;
180190

test/run-smoke-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export PROJECT_PATH
1717
export SPACETIME_DIR="$PWD/.."
1818

1919
export SPACETIME_SKIP_CLIPPY=1
20-
CONTAINER_NAME=$(docker ps | grep node | awk '{print $NF}')
20+
CONTAINER_NAME=$(docker ps | grep "\-node-" | awk '{print $NF}')
2121
docker logs "$CONTAINER_NAME"
2222

2323
rustup update

test/tests/autoinc2.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ do_test() {
1414
create_project
1515

1616
cat > "${PROJECT_PATH}/src/lib.rs" << EOF
17+
use std::error::Error;
1718
use spacetimedb::{println, spacetimedb};
1819
1920
#[spacetimedb(table)]
@@ -26,15 +27,16 @@ pub struct Person {
2627
}
2728
2829
#[spacetimedb(reducer)]
29-
pub fn add_new(name: String) {
30-
let value = Person::insert(Person { key_col: 0, name }).unwrap();
30+
pub fn add_new(name: String) -> Result<(), Box<dyn Error>> {
31+
let value = Person::insert(Person { key_col: 0, name })?;
3132
println!("Assigned Value: {} -> {}", value.key_col, value.name);
33+
Ok(())
3234
}
3335
3436
#[spacetimedb(reducer)]
3537
pub fn update(name: String, new_id: REPLACE_VALUE) {
3638
Person::delete_by_name(&name);
37-
let value = Person::insert(Person { key_col: new_id, name });
39+
let _value = Person::insert(Person { key_col: new_id, name });
3840
}
3941
4042
#[spacetimedb(reducer)]

test/tests/zz_docker-restart-repeating-reducer.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ fn init() {
2323
pub fn my_repeating_reducer(prev: Timestamp) {
2424
println!("Invoked: ts={:?}, delta={:?}", Timestamp::now(), prev.elapsed());
2525
}
26+
27+
#[spacetimedb(reducer)]
28+
pub fn dummy() {}
2629
EOF
2730

2831
run_test cargo run publish -s -d --project-path "$PROJECT_PATH" --clear-database
2932
[ "1" == "$(grep -c "reated new database" "$TEST_OUT")" ]
3033
IDENT="$(grep "reated new database" "$TEST_OUT" | awk 'NF>1{print $NF}')"
3134

32-
CONTAINER_NAME=$(docker ps | grep node | awk '{print $NF}')
35+
CONTAINER_NAME=$(docker ps | grep "\-node-" | awk '{print $NF}')
3336
run_test docker kill $CONTAINER_NAME
3437
run_test cargo build -p spacetimedb-standalone --release
3538
run_test docker-compose start node
3639
sleep 10
3740

41+
run_test cargo run call "$IDENT" dummy
42+
sleep 4
3843

3944
run_test cargo run logs "$IDENT"
4045
LINES="$(grep -c "Invoked" "$TEST_OUT")"

0 commit comments

Comments
 (0)