Skip to content

Commit e7cf714

Browse files
chrisbobbegnprice
authored andcommitted
exampleData: Reserve some message, stream, and user IDs for snapshot tests
In generateInboundEventEditSequence-test.js, when we build state objects from eg.plusReduxState, the data we add includes some constant message, stream, and user IDs. Constant because they end up appearing in test snapshots, and we want those snapshots to be stable. This is a problem when the data we're building from already claims those IDs, for example, by saying that a stream with ID 1 exists and that we have a subscription for it. Since eg.plusReduxState uses random IDs, this has been happening some small fraction of the time, resulting in flakes where the snapshot says a stream is *not* subscribed, but the input data says it *is*. That's #5415. So, to fix, reserve a small section of stream IDs, including 1 and 2, which we use in the mentioned snapshot tests, so that eg.plusReduxState never chooses them. And similarly reserve a range of message and user IDs, too. As suggested by Greg: #5415 (comment) In another approach to fix those flakes, we might have instead built on eg.plusReduxState by erasing some of it first, removing spreads like the one in streams: [...eg.plusReduxState.streams, stream1, stream2], But as we mentioned in 371e9b4, that'd risk corrupting the state we get from eg.plusReduxState. That's the only example state that claims to offer a realistic uncorrupted state with server data, and it's good not to interfere with that guarantee if we can avoid it. (For example, if eg.plusReduxState grows a reference to a stream in `muteModel`, it'd be corrupt if that stream is absent in the `streams` state.) It's too bad that the easy, natural thing to do is to omit the spreads. Fixes: #5415
1 parent 89de470 commit e7cf714

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ const makeAvatarUrl = (tag: string) =>
142142
// here with a full-blown URL object in the first place to prevent that.
143143
new UploadedAvatarURL(new URL(`https://zulip.example.org/yo/avatar-${tag}.png`));
144144

145+
// Why start at 11? To reserve IDs 1 through 10 for use as constants in
146+
// snapshot tests.
145147
const randUserId: () => UserId = (
146148
mk => () =>
147149
makeUserId(mk())
148-
)(makeUniqueRandInt('user IDs', 10000));
150+
)(makeUniqueRandInt('user IDs', 10000, 11));
149151
const userOrBotProperties = (args: UserOrBotPropertiesArgs) => {
150152
const user_id = args.user_id != null ? makeUserId(args.user_id) : randUserId();
151153
const randName = randString();
@@ -288,7 +290,9 @@ export const crossRealmBot: CrossRealmBot = makeCrossRealmBot({
288290
* Streams and subscriptions
289291
*/
290292

291-
const randStreamId: () => number = makeUniqueRandInt('stream IDs', 1000);
293+
// Why start at 11? To reserve IDs 1 through 10 for use as constants in
294+
// snapshot tests.
295+
const randStreamId: () => number = makeUniqueRandInt('stream IDs', 1000, 11);
292296
export const makeStream = (
293297
args: {|
294298
stream_id?: number,
@@ -418,7 +422,9 @@ const messagePropertiesFromSender = (user: User) => {
418422
});
419423
};
420424

421-
const randMessageId: () => number = makeUniqueRandInt('message ID', 10000000);
425+
// Why start at 11? To reserve IDs 1 through 10 for use as constants in
426+
// snapshot tests.
427+
const randMessageId: () => number = makeUniqueRandInt('message ID', 10000000, 11);
422428

423429
/**
424430
* A PM, by default a 1:1 from eg.otherUser to eg.selfUser.

0 commit comments

Comments
 (0)