Skip to content

Commit

Permalink
fix c tests to do win on site id note value
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Oct 26, 2023
1 parent 1c4dc0f commit 6ec6a85
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions core/src/rows-impacted.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static void testCreateThatDoesNotChangeAnything() {
printf("\t\e[0;32mSuccess\e[0m\n");
}

static void testValueWin() {
static void testValueWouldWinButSiteIdLoses() {
printf("ValueWin\n");
int rc = SQLITE_OK;
char *err = 0;
Expand All @@ -326,10 +326,37 @@ static void testValueWin() {
rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
rc += sqlite3_exec(db,
"INSERT INTO crsql_changes VALUES ('foo', X'010901', 'b', "
"3, 1, 1, NULL, 1, 1)",
"3, 1, 1, X'00000000000000000000000000000000', 1, 1)",
0, 0, &err);
sqlite3_prepare_v2(db, "SELECT crsql_rows_impacted()", -1, &pStmt, 0);
sqlite3_step(pStmt);
// value is greater but site id lower, a loss and now rows changed.
assert(sqlite3_column_int(pStmt, 0) == 0);
sqlite3_finalize(pStmt);
rc += sqlite3_exec(db, "COMMIT", 0, 0, 0);
assert(rc == SQLITE_OK);

crsql_close(db);
printf("\t\e[0;32mSuccess\e[0m\n");
}

static void testSiteIdWin() {
printf("SiteIdWin\n");
int rc = SQLITE_OK;
char *err = 0;
sqlite3 *db = createDb();
sqlite3_stmt *pStmt = 0;

rc = sqlite3_exec(db, "INSERT INTO foo VALUES (1, 2)", 0, 0, 0);

rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
rc += sqlite3_exec(db,
"INSERT INTO crsql_changes VALUES ('foo', X'010901', 'b', "
"3, 1, 1, X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 1, 1)",
0, 0, &err);
sqlite3_prepare_v2(db, "SELECT crsql_rows_impacted()", -1, &pStmt, 0);
sqlite3_step(pStmt);
// site id is larger, a win
assert(sqlite3_column_int(pStmt, 0) == 1);
sqlite3_finalize(pStmt);
rc += sqlite3_exec(db, "COMMIT", 0, 0, 0);
Expand Down Expand Up @@ -374,7 +401,8 @@ void rowsImpactedTestSuite() {
testUpdateThatDoesNotChangeAnything();
testDeleteThatDoesNotChangeAnything();
testCreateThatDoesNotChangeAnything();
testValueWin();
testValueWouldWinButSiteIdLoses();
testSiteIdWin();
testClockWin();
testDelete();
}

0 comments on commit 6ec6a85

Please sign in to comment.