Skip to content

Commit a04b44e

Browse files
committed
msglist test: Fix a state leak from mutating eg.selfUser
Fixes #1712. Our CI has been failing in this test file since yesterday; this change fixes that. This test had been having the store handle a RealmUserUpdateEvent affecting `eg.selfUser`. That means the store mutates the actual User object it has... which, in this test context, means the value that `eg.selfUser` is bound to as a final variable. As a result, when the test gets cleaned up with testBinding.reset, the store gets discarded as usual so that the next test will get a fresh store... but the User object at `eg.selfUser` is still the one that's been mutated by this test. That's buggy in principle. Concretely, here, it causes the self-user to have a non-null avatar. When a later test sends a message and causes an outbox-message to appear in the tree, that results in a NetworkImage. And that throws an error, because no HttpClient provider has been set, because that latter test wasn't expecting to create any `NetworkImage`s. That's the failure we've been seeing in CI. It's still a bit mysterious why this had previously been working (or anyway these tests hadn't been failing). It started failing with an upstream change merged yesterday, which makes changes to NetworkImage that look innocuous: its `==` and `hashCode` become finer-grained, and its `toString` more detailed. In any case, the bug is ours to fix. It'd also be good to follow up here by systematically preventing this sort of state leak between tests. But that comes after getting our CI passing again.
1 parent a3bbee9 commit a04b44e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/widgets/message_list_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,15 +1693,18 @@ void main() {
16931693
}
16941694
}
16951695

1696+
final user = eg.user();
1697+
16961698
Future<void> handleNewAvatarEventAndPump(WidgetTester tester, String avatarUrl) async {
1697-
await store.handleEvent(RealmUserUpdateEvent(id: 1, userId: eg.selfUser.userId, avatarUrl: avatarUrl));
1699+
await store.handleEvent(RealmUserUpdateEvent(id: 1, userId: user.userId, avatarUrl: avatarUrl));
16981700
await tester.pump();
16991701
}
17001702

17011703
prepareBoringImageHttpClient();
17021704

1703-
await setupMessageListPage(tester, messageCount: 10);
1704-
checkResultForSender(eg.selfUser.avatarUrl);
1705+
await setupMessageListPage(tester, users: [user],
1706+
messages: [eg.streamMessage(sender: user)]);
1707+
checkResultForSender(user.avatarUrl);
17051708

17061709
await handleNewAvatarEventAndPump(tester, '/foo.png');
17071710
checkResultForSender('/foo.png');

0 commit comments

Comments
 (0)