diff --git a/integration-tests/bats/branch-activity.bats b/integration-tests/bats/branch-activity.bats new file mode 100644 index 0000000000..941f45875b --- /dev/null +++ b/integration-tests/bats/branch-activity.bats @@ -0,0 +1,70 @@ +#!/usr/bin/env bats +load $BATS_TEST_DIRNAME/helper/common.bash +load $BATS_TEST_DIRNAME/helper/query-server-common.bash + +setup() { + setup_no_dolt_init + + mkdir repo1 + cd repo1 + dolt init + dolt sql -q "CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR(50));" + dolt sql -q "INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob');" + dolt commit -Am "Initial commit" + dolt branch feature1 + dolt branch feature2 + + cd ../ + start_sql_server +} + +teardown() { + cleanup_idle_connections + + stop_sql_server 1 && sleep 0.5 + teardown_common +} + +# Helper function to start an idle dolt sql connection on a specific branch +start_idle_connection() { + local branch=$1 + + # Do nothing connection to keep the branch activ + dolt sql --use-db "repo1/$branch" & + local pid=$! + + # Store the PID for cleanup + echo $pid >> $BATS_TMPDIR/idle_connections_$$ + + return $pid +} + +# Helper function to cleanup idle connections +cleanup_idle_connections() { + if [ -f $BATS_TMPDIR/idle_connections_$$ ]; then + while read pid; do + kill $pid 2>/dev/null || true + done < $BATS_TMPDIR/idle_connections_$$ + fi +} + +@test "branch-activity: multi-client branch activity tracking" { + cd repo1 + + # Start idle connections on different branches to simulate active clients + start_idle_connection "main" + start_idle_connection "feature1" + start_idle_connection "feature2" + + # Wait a moment for connections to establish + sleep 1 + + # Now test that branch activity table shows the activity + run dolt sql -q "SELECT COUNT(*) FROM dolt_branch_activity WHERE last_read IS NOT NULL;" + [ $status -eq 0 ] + + # Should have at least some branches with read activity + run dolt sql -q "SELECT branch FROM dolt_branch_activity WHERE last_read IS NOT NULL ORDER BY branch;" + [ $status -eq 0 ] + +} \ No newline at end of file diff --git a/integration-tests/bats/helper/local-remote.bash b/integration-tests/bats/helper/local-remote.bash index 50bb6c41f7..15b3a6bbe3 100644 --- a/integration-tests/bats/helper/local-remote.bash +++ b/integration-tests/bats/helper/local-remote.bash @@ -144,6 +144,7 @@ SKIP_SERVER_TESTS=$(cat <<-EOM ~admin-conjoin.bats~ ~admin-archive-inspect.bats~ ~nonlocal.bats~ +~branch-activity.bats~ EOM )