Skip to content

Commit

Permalink
Enable restart tests (#35)
Browse files Browse the repository at this point in the history
* 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 <cloutiertyler@aol.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
  • Loading branch information
3 people committed Aug 1, 2023
1 parent aabf5ad commit fb57eb7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Start containers
run: docker compose up -d
- name: Run smoketests
run: test/run-smoke-tests.sh -x bitcraftmini-pretest zz_docker-restart-repeating-reducer zz_docker-restart-module zz_docker-restart-sql
run: test/run-smoke-tests.sh -x bitcraftmini-pretest
- name: Stop containers
if: always()
run: docker compose down
Expand Down
8 changes: 6 additions & 2 deletions crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,12 @@ impl Inner {
col_id: &ColId,
value: &'a AlgebraicValue,
) -> super::Result<IterByColEq> {
let tx_state = self.tx_state.as_ref().unwrap();
if let Some(inserted_rows) = tx_state.index_seek(table_id, col_id, value) {
if let Some(inserted_rows) = self
.tx_state
.as_ref()
.and_then(|tx_state| tx_state.index_seek(table_id, col_id, value))
{
let tx_state = self.tx_state.as_ref().unwrap();
Ok(IterByColEq::Index(IndexIterByColEq {
value,
col_id: *col_id,
Expand Down
10 changes: 10 additions & 0 deletions crates/core/src/host/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ impl HostController {
Ok(module_host)
}

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

Expand Down
2 changes: 1 addition & 1 deletion test/run-smoke-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export PROJECT_PATH
export SPACETIME_DIR="$PWD/.."

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

rustup update
Expand Down
8 changes: 5 additions & 3 deletions test/tests/autoinc2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ do_test() {
create_project

cat > "${PROJECT_PATH}/src/lib.rs" << EOF
use std::error::Error;
use spacetimedb::{println, spacetimedb};
#[spacetimedb(table)]
Expand All @@ -26,15 +27,16 @@ pub struct Person {
}
#[spacetimedb(reducer)]
pub fn add_new(name: String) {
let value = Person::insert(Person { key_col: 0, name }).unwrap();
pub fn add_new(name: String) -> Result<(), Box<dyn Error>> {
let value = Person::insert(Person { key_col: 0, name })?;
println!("Assigned Value: {} -> {}", value.key_col, value.name);
Ok(())
}
#[spacetimedb(reducer)]
pub fn update(name: String, new_id: REPLACE_VALUE) {
Person::delete_by_name(&name);
let value = Person::insert(Person { key_col: new_id, name });
let _value = Person::insert(Person { key_col: new_id, name });
}
#[spacetimedb(reducer)]
Expand Down
7 changes: 6 additions & 1 deletion test/tests/zz_docker-restart-repeating-reducer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ fn init() {
pub fn my_repeating_reducer(prev: Timestamp) {
println!("Invoked: ts={:?}, delta={:?}", Timestamp::now(), prev.elapsed());
}
#[spacetimedb(reducer)]
pub fn dummy() {}
EOF

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

CONTAINER_NAME=$(docker ps | grep node | awk '{print $NF}')
CONTAINER_NAME=$(docker ps | grep "\-node-" | awk '{print $NF}')
run_test docker kill $CONTAINER_NAME
run_test cargo build -p spacetimedb-standalone --release
run_test docker-compose start node
sleep 10

run_test cargo run call "$IDENT" dummy
sleep 4

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

0 comments on commit fb57eb7

Please sign in to comment.