Skip to content

Added integration tests for sending events to Zulip and mock server - #790

Open
cuba0001 wants to merge 2 commits into
rust-lang:mainfrom
cuba0001:zulip-integration-tests
Open

Added integration tests for sending events to Zulip and mock server#790
cuba0001 wants to merge 2 commits into
rust-lang:mainfrom
cuba0001:zulip-integration-tests

Conversation

@cuba0001

Copy link
Copy Markdown
Contributor

No description provided.

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, thank you, this looks good! One thing I'd like to modify is to remember the received messages "dynamically", so that we can check at the end of each test whether we got any expected messages or not. But for that we won't be able to use received_requests from wiremock anymore.

View changes since this review

Comment thread src/bors/handlers/review.rs Outdated
ctx.get_next_comment_text(()).await?,
@"Tree closed for PRs with priority less than 5."
);
assert_eq!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It gets super annoying to update these test assertions when they change, which is why I prefer to use insta as much as possible.

Could you please turn this into something like:

let messages = ctx.zulip_messages().await?;
insta::assert_debug_snapshot(messages, @"");

Comment thread src/bors/handlers/review.rs Outdated
ctx.get_next_comment_text(()).await?,
@"Tree closed for PRs with priority less than 5."
);
assert_eq!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here. Could you please add a comment here that says that we want to ensure that the message gets @ stripped away? Thanks!

Comment thread src/bors/handlers/review.rs Outdated
ctx.get_next_comment_text(()).await?,
@"@default-user: :key: Insufficient privileges: not in review users"
);
assert!(ctx.zulip_messages().await?.is_empty());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please add this to BorsTester::finish? To ensure that we didn't get any unexpected Zulip messages in tests. I think it could be added to assert_empty_queues.

To make this work, it would be good to change async fn zulip_messages to always take the received message, and flush it from the Zulip message queue. Otherwise we won't be able to recognize if a test read the message or not.

@rustbot

This comment has been minimized.

@cuba0001
cuba0001 force-pushed the zulip-integration-tests branch from fd3cff8 to 0a1cb3c Compare July 30, 2026 16:37
@rustbot

rustbot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@cuba0001

Copy link
Copy Markdown
Contributor Author

@Kobzol

Done! Added queue for received messages, added a check for receiving unexpected messages, also it required to add a check of messages count to the existing tests (which also flushes received messages), replaced assertions with insta, comment that says a message gets @ stripped away from reason.

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Left a few more comments based on the edits.

View changes since this review

Comment thread src/tests/mock/zulip.rs
let mock_server = MockServer::start().await;
let received_messages = Arc::new(Mutex::new(Vec::new()));

Mock::given(any())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please put back the explicit messages URL? It both helps the reader understand what is the test mocking, and it also ensures that we won't be mocking unexpected endpoints by accident.

Comment thread src/tests/mock/zulip.rs
move |request: &Request| {
received_messages
.lock()
.push(ZulipMessage::try_from(request));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's panic here if the message cannot be parsed, rather than putting results into the queue. The bors tester infrastructure should be able to detect panics within the mocked server.

Comment thread src/tests/mock/zulip.rs
}

pub(super) fn take_received_messages(&self) -> anyhow::Result<Vec<ZulipMessage>> {
let received_messages: Vec<_> = self.received_messages.lock().drain(..).collect();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(this code should be removed based on my previous suggestion, but here's a tip: you can collect a vec of results into a result of a vec)

Suggested change
let received_messages: Vec<_> = self.received_messages.lock().drain(..).collect();
let received_messages: Vec<ZulipMessage> = self.received_messages.lock().drain(..).collect::<anyhow::Result<Vec<ZulipMessage>>()?;

Comment thread src/tests/mock/zulip.rs
Ok(messages)
}

pub(super) fn assert_empty_queue(&self) -> anyhow::Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should do the same thing as the GitHub mock, to stop the mocked server (the function will have to become async):

self.mock_server.reset().await;
drop(self.mock_server);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants