Skip to content

Commit

Permalink
fix: Catch database exceptions at the end of transactions. (serverpod…
Browse files Browse the repository at this point in the history
  • Loading branch information
hampuslavin authored Oct 15, 2024
1 parent 9c079a7 commit 0880992
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 250 deletions.
8 changes: 7 additions & 1 deletion packages/serverpod_test/lib/src/transaction_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class TransactionManager {
await _endTransactionScopeCompleter.future;
},
isUserCall: false,
),
).catchError((error, stackTrace) {
// no-op:
// If a database exception occurred during the transaction,
// but the exception was caught and the transactions was allowed to complete,
// then the transaction will rethrow it when it completes.
// This has to be caught, otherwise the dart test runner will fail the test suite.
}),
);

await transactionStartedCompleter.future;
Expand Down
4 changes: 4 additions & 0 deletions tests/serverpod_test_server/config/passwords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ production:
database: 'password'
redis: 'password'
serviceSecret: 'super_SECRET_password'
test:
database: 'password'
redis: 'password'
serviceSecret: 'super_SECRET_password'
30 changes: 30 additions & 0 deletions tests/serverpod_test_server/config/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Duplicate of production.yaml
# The test tools use test by default, but the other integration tests use production as run mode
apiServer:
port: 8080
publicHost: serverpod_test_server
publicPort: 8080
publicScheme: http

insightsServer:
port: 8081
publicHost: serverpod_test_server
publicPort: 8081
publicScheme: http

webServer:
port: 8082
publicHost: serverpod_test_server
publicPort: 8082
publicScheme: http

database:
host: postgres
port: 5432
name: serverpod_test
user: postgres

redis:
enabled: true
host: redis
port: 6379
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:serverpod/serverpod.dart';
import 'package:test/test.dart';

import 'test_tools/serverpod_test_tools.dart';
Expand Down Expand Up @@ -59,6 +58,5 @@ void main() {
);
});
},
runMode: ServerpodRunMode.production,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,5 @@ void main() {
});
});
},
runMode: ServerpodRunMode.production,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ void main() {
});
});
},
runMode: ServerpodRunMode.production,
);

withServerpod(
Expand Down Expand Up @@ -168,7 +167,6 @@ void main() {
});
});
},
runMode: ServerpodRunMode.production,
rollbackDatabase: RollbackDatabase.afterEach,
);

Expand Down Expand Up @@ -200,7 +198,6 @@ void main() {
expect(simpleDatas[1].num, 123);
});
},
runMode: ServerpodRunMode.production,
rollbackDatabase: RollbackDatabase.afterAll,
);

Expand All @@ -214,7 +211,6 @@ void main() {
expect(simpleDatas, hasLength(0));
});
},
runMode: ServerpodRunMode.production,
);
});

Expand All @@ -240,7 +236,6 @@ void main() {
});
},
rollbackDatabase: RollbackDatabase.afterAll,
runMode: ServerpodRunMode.production,
);

withServerpod(
Expand All @@ -253,7 +248,6 @@ void main() {
expect(simpleDatas, hasLength(0));
});
},
runMode: ServerpodRunMode.production,
);
});

Expand All @@ -280,7 +274,6 @@ void main() {
});
},
rollbackDatabase: RollbackDatabase.afterAll,
runMode: ServerpodRunMode.production,
);

withServerpod(
Expand All @@ -294,7 +287,6 @@ void main() {
expect(simpleDatas, hasLength(0));
});
},
runMode: ServerpodRunMode.production,
);
});
});
Expand Down Expand Up @@ -326,7 +318,6 @@ void main() {
expect(simpleDatas[1].num, 123);
});
},
runMode: ServerpodRunMode.production,
rollbackDatabase: RollbackDatabase.disabled,
);

Expand All @@ -351,7 +342,6 @@ void main() {
expect(simpleDatas[1].num, 123);
});
},
runMode: ServerpodRunMode.production,
rollbackDatabase: RollbackDatabase.disabled,
);
});
Expand All @@ -377,7 +367,6 @@ void main() {
});
},
rollbackDatabase: RollbackDatabase.disabled,
runMode: ServerpodRunMode.production,
);

withServerpod(
Expand All @@ -399,7 +388,6 @@ void main() {
});
},
rollbackDatabase: RollbackDatabase.disabled,
runMode: ServerpodRunMode.production,
);
});

Expand All @@ -426,7 +414,6 @@ void main() {
});
},
rollbackDatabase: RollbackDatabase.disabled,
runMode: ServerpodRunMode.production,
);
});
}
Loading

0 comments on commit 0880992

Please sign in to comment.