Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions test/features/meshtastic/mesh_chat_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ void main() {
Future<void> settle() =>
Future<void>.delayed(const Duration(milliseconds: 150));

/// Waits until [store] holds [expected] messages.
///
/// `_add` writes fire-and-forget and only adopts a message into the in-memory
/// list once the insert answers (mesh_chat_controller.dart:322-328), so both
/// halves of what these tests assert land *after* the controller has been
/// handed the packet. A fixed delay is therefore a guess about how fast the
/// machine is: 150 ms was enough on a laptop and not on CI, where the last
/// dozen inserts arrived after the test had already closed the database and
/// the failure read as `This database has already been closed`.
Future<void> drained(MeshStore store, int expected) async {
final deadline = DateTime.now().add(const Duration(seconds: 10));
while (DateTime.now().isBefore(deadline)) {
if ((await store.messages(limit: 100000)).length >= expected) return;
await Future<void>.delayed(const Duration(milliseconds: 10));
}
}

test('keeps the newest messages first', () async {
final (controller, service, _) = await makeController();
for (var i = 0; i < 10; i++) {
Comment on lines 81 to 83

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · critical
在 'keeps the newest messages first' 測試案例中,store 被解構為 _,導致後續呼叫 drained(store, ...) 時會出現編譯錯誤(Undefined name 'store')。

Suggestion:

Suggested change
test('keeps the newest messages first', () async {
final (controller, service, _) = await makeController();
for (var i = 0; i < 10; i++) {
test('keeps the newest messages first', () async {
final (controller, service, store) = await makeController();
for (var i = 0; i < 10; i++) {

Expand All @@ -78,7 +95,7 @@ void main() {
for (var i = 0; i < MeshChatController.windowSize + 20; i++) {
service.messages.add(message('m$i', seconds: i));
}
await settle();
await drained(store, MeshChatController.windowSize + 20);

expect(controller.messages, hasLength(MeshChatController.windowSize));
// The store keeps everything — the window is a view, not a retention cap.
Expand All @@ -91,7 +108,7 @@ void main() {
test('persists the log and reloads it after a restart', () async {
final (controller, service, store) = await makeController();
service.messages.add(message('hello'));
await settle();
await drained(store, 1);
controller.dispose();

final (restored, _, _) = await makeController(store);
Expand Down
24 changes: 14 additions & 10 deletions test/tool/colorize_logs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ const _esc = 27;
/// Runs the script over [input]. Without a pty, stdout is not a terminal.
String run(String input, {bool tty = false}) {
final script = '${Directory.current.path}/tool/internal/colorize_logs.sh';
final piped = 'printf %s ${_quote(input)} | $script';
// `script` lends the pipeline a pty, which is the only way to exercise the
// branch that decides whether to emit anything at all — and its argument
// order is the opposite on the two platforms this repository builds on.
// BSD takes the typescript file first and the command after it; util-linux
// wants the command behind `-c` and the file last. Written for BSD only, it
// passed on a laptop and hung Linux CI into a failure with no message.
final result = tty
// `script` lends the pipeline a pty, which is the only way to exercise
// the branch that decides whether to emit anything at all.
? Process.runSync('script', [
'-q',
'/dev/null',
'bash',
'-c',
'printf %s ${_quote(input)} | $script',
])
: Process.runSync('bash', ['-c', 'printf %s ${_quote(input)} | $script']);
? Process.runSync(
'script',
Platform.isMacOS
? ['-q', '/dev/null', 'bash', '-c', piped]
: ['-q', '-c', piped, '/dev/null'],
)
: Process.runSync('bash', ['-c', piped]);
expect(result.exitCode, 0, reason: result.stderr.toString());
return result.stdout.toString();
}
Expand Down
8 changes: 7 additions & 1 deletion tool/commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ if ((run_gates)); then
note 'inputs, so an unchanged tree costs seconds instead of a minute.'
printf '\n'
if tool/check.sh; then
ok 'every gate passed — this is what CI will do'
ok "every gate passed, on $(uname -s)"
# Said, because the difference has already cost a red CI: this runs CI's
# command list on *this* machine, and the runner is Linux. A test that
# shells out meets a different sed, a different awk and a different
# `script`, and passes here while failing there.
[[ "$(uname -s)" == Linux ]] ||
note 'CI runs Linux — a test that shells out can still differ there'
else
block 'a gate failed — CI will fail the same way'
fi
Expand Down
Loading