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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ jobs:

- name: Run tests
if: runner.os != 'Linux'
run: cargo nextest run --workspace --locked
run: cargo nextest run --workspace --locked --no-fail-fast

- name: Test iOS text input on the host
if: runner.os == 'macOS'
run: cargo test -p gpui-ios --lib --locked

- name: Run tests under Xvfb
if: runner.os == 'Linux'
run: xvfb-run -a cargo nextest run --workspace --locked
run: xvfb-run -a cargo nextest run --workspace --locked --no-fail-fast

macos-clippy:
name: macOS arm64 / clippy
Expand Down
88 changes: 25 additions & 63 deletions crates/runtime/src/app/pull_requests_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,13 @@ fn acked(
command: Command,
) -> Result<CommandResponse, tcode_protocol::ProtocolError> {
state.dispatch_command(cx, id, command);
let deadline = std::time::Instant::now() + Duration::from_secs(5);
loop {
cx.run_until_parked();
if let Some(result) = cx
.drain_outgoing()
.into_iter()
.find_map(|message| match message {
tcode_protocol::HostMessage::Ack { id: acked, result } if acked == id => {
Some(result)
}
_ => None,
})
{
return result;
cx.run_until_sent(|message| match message {
tcode_protocol::HostMessage::Ack { id: acked, result } if *acked == id => {
Some(result.clone())
}
assert!(
std::time::Instant::now() < deadline,
"the command was answered"
);
}
_ => None,
})
.0
}

struct HostReply {
Expand Down Expand Up @@ -597,7 +584,7 @@ fn discovery_answers_local_branches_and_drops_a_linked_worktree_result_after_bra
let _server = fixture.serve(move |exchange| {
let sent: Value = serde_json::from_slice(&exchange.body).unwrap();
arrived.send(sent).unwrap();
resume.recv_timeout(Duration::from_secs(5)).unwrap();
resume.recv_timeout(HOST_DEADLINE).unwrap();
exchange.reply(
200,
"",
Expand Down Expand Up @@ -672,7 +659,7 @@ fn a_project_move_waits_for_discovery_to_leave_its_root() {
let _server = fixture.serve(move |exchange| {
if let Some((arrived, resume)) = held.lock().unwrap().take() {
arrived.send(()).unwrap();
resume.recv_timeout(Duration::from_secs(5)).unwrap();
resume.recv_timeout(HOST_DEADLINE).unwrap();
}
exchange.reply(200, "", br#"{"data":{"repository":{"h0":{"nodes":[]}}}}"#);
});
Expand Down Expand Up @@ -1266,28 +1253,14 @@ fn reads_answer_only_a_linked_pull_request_and_a_synced_change_reads_it_fresh()
read: tcode_protocol::PullRequestRead::Conversation,
}),
);
let deadline = std::time::Instant::now() + Duration::from_secs(5);
loop {
cx.run_until_parked();
if let Some(result) =
cx.drain_outgoing()
.into_iter()
.find_map(|message| match message {
tcode_protocol::HostMessage::QueryResult { id, result }
if id == next_id =>
{
Some(result)
}
_ => None,
})
{
return result;
let read_id = next_id;
cx.run_until_sent(|message| match message {
tcode_protocol::HostMessage::QueryResult { id, result } if *id == read_id => {
Some(result.clone())
}
assert!(
std::time::Instant::now() < deadline,
"the read was answered"
);
}
_ => None,
})
.0
};

sweep(&state, &mut cx);
Expand Down Expand Up @@ -1634,28 +1607,17 @@ fn a_review_draft_is_its_accounts_and_an_unanswered_submission_waits_for_a_later
let mut answer = |state: &TestEntity, cx: &mut TestAppContext, payload| {
next_id += 1;
state.deliver(cx, next_id, payload);
let deadline = std::time::Instant::now() + Duration::from_secs(5);
loop {
cx.run_until_parked();
if let Some(result) =
cx.drain_outgoing()
.into_iter()
.find_map(|message| match message {
tcode_protocol::HostMessage::Ack { id, result } if id == next_id => {
Some(result.map(|response| json!(response)))
}
tcode_protocol::HostMessage::QueryResult { id, result }
if id == next_id =>
{
Some(result.map(|response| json!(response)))
}
_ => None,
})
{
return result;
let answer_id = next_id;
cx.run_until_sent(|message| match message {
tcode_protocol::HostMessage::Ack { id, result } if *id == answer_id => {
Some(result.clone().map(|response| json!(response)))
}
assert!(std::time::Instant::now() < deadline, "it was answered");
}
tcode_protocol::HostMessage::QueryResult { id, result } if *id == answer_id => {
Some(result.clone().map(|response| json!(response)))
}
_ => None,
})
.0
};
let body = |body: &str| {
tcode_protocol::ClientPayload::Command(Command::EditPullRequestReviewDraft {
Expand Down
41 changes: 35 additions & 6 deletions crates/runtime/src/app/test_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ use tcode_protocol::{ClientMessage, ClientPayload, Command, HostMessage, decode_
)]
pub(super) mod github_fixture;

/// How long a test waits on the host before giving up. It only bounds a hang:
/// a test that drives real git processes takes several seconds on a loaded
/// Windows runner.
pub(super) const HOST_DEADLINE: Duration = Duration::from_secs(30);

pub(super) struct TestStore(SessionStore);

impl TestStore {
Expand Down Expand Up @@ -89,13 +94,13 @@ impl TestAppContext {
.as_ref()
.and_then(Weak::upgrade)
.expect("test state must outlive its context");
let deadline = Instant::now() + Duration::from_secs(5);
let deadline = Instant::now() + HOST_DEADLINE;
let mut store_flushed = false;

loop {
assert!(
Instant::now() < deadline,
"test host failed to park within five seconds"
"test host failed to park within {HOST_DEADLINE:?}"
);
let mut had_work = false;
while let Ok(message) = self.mailbox_rx.try_recv() {
Expand Down Expand Up @@ -135,7 +140,7 @@ impl TestAppContext {
/// Park repeatedly until `done` observes the state a background chain
/// must reach.
pub(super) fn run_until(&mut self, mut done: impl FnMut(&TestClientState) -> bool) {
let deadline = Instant::now() + Duration::from_secs(5);
let deadline = Instant::now() + HOST_DEADLINE;
loop {
self.run_until_parked();
let state = self
Expand All @@ -148,7 +153,31 @@ impl TestAppContext {
}
assert!(
Instant::now() < deadline,
"test host condition not reached within five seconds"
"test host condition not reached within {HOST_DEADLINE:?}"
);
std::thread::sleep(Duration::from_millis(1));
}
}

/// Park repeatedly until `pick` finds what the test waits for among the
/// messages the host sends; return it with every message drained on the
/// way.
pub(super) fn run_until_sent<T>(
&mut self,
mut pick: impl FnMut(&HostMessage) -> Option<T>,
) -> (T, Vec<HostMessage>) {
let deadline = Instant::now() + HOST_DEADLINE;
let mut sent = Vec::new();
loop {
self.run_until_parked();
let seen = sent.len();
sent.extend(self.drain_outgoing());
if let Some(found) = sent[seen..].iter().find_map(&mut pick) {
return (found, sent);
}
assert!(
Instant::now() < deadline,
"the host did not send what the test waits for within {HOST_DEADLINE:?}"
);
std::thread::sleep(Duration::from_millis(1));
}
Expand All @@ -163,14 +192,14 @@ impl TestAppContext {
.as_ref()
.and_then(Weak::upgrade)
.expect("test state must outlive its context");
let deadline = Instant::now() + Duration::from_secs(5);
let deadline = Instant::now() + HOST_DEADLINE;
let message = loop {
if let Ok(message) = self.mailbox_rx.try_recv() {
break message;
}
assert!(
Instant::now() < deadline,
"nothing reached the mailbox within five seconds"
"nothing reached the mailbox within {HOST_DEADLINE:?}"
);
std::thread::sleep(Duration::from_millis(1));
};
Expand Down
54 changes: 16 additions & 38 deletions crates/runtime/src/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9044,18 +9044,13 @@ fn index_and_visit_changes_cross_the_wire_one_thread_at_a_time() {
tcode_client::attachment::AttachmentPolicy::LOCAL,
)
});
cx.run_until_parked();
let archived = cx
.drain_outgoing()
.into_iter()
.find_map(|message| match message {
HostMessage::QueryResult {
id: 3,
result: Ok(QueryResponse::ArchivedSessions(archived)),
} => Some(archived),
_ => None,
})
.expect("archived list reply");
let (archived, _) = cx.run_until_sent(|message| match message {
HostMessage::QueryResult {
id: 3,
result: Ok(QueryResponse::ArchivedSessions(archived)),
} => Some(archived.clone()),
_ => None,
});
assert_eq!(archived.revision, summary_revision);
assert_eq!(archived.sessions[0].title, "Archived rename");

Expand Down Expand Up @@ -9976,21 +9971,11 @@ fn send_to_host(
/// Run the host until it answered client message `id` and parked, and
/// return every message it serialized since the last drain.
fn answered(cx: &mut TestAppContext, id: u64) -> Vec<HostMessage> {
let deadline = Instant::now() + Duration::from_secs(30);
let mut messages = Vec::new();
loop {
cx.run_until_parked();
messages.extend(cx.drain_outgoing());
if messages.iter().any(|message| {
matches!(message, HostMessage::Ack { id: reply, .. } | HostMessage::QueryResult { id: reply, .. } if *reply == id)
}) {
return messages;
}
assert!(
Instant::now() < deadline,
"the host did not answer message {id} within thirty seconds"
);
}
cx.run_until_sent(|message| {
matches!(message, HostMessage::Ack { id: reply, .. } | HostMessage::QueryResult { id: reply, .. } if *reply == id)
.then_some(())
})
.1
}

/// Send `payload` through the host pipe as client message `id`, and return
Expand Down Expand Up @@ -12215,17 +12200,10 @@ fn github_secret_command_persists_separately_and_settings_never_replicate_it() {
email: None,
},
);
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
loop {
cx.run_until_parked();
if cx.drain_outgoing().iter().any(|message| matches!(message, HostMessage::Ack { id: 644, result: Err(error) } if error.code == "settings_write_failed")) {
break;
}
assert!(
std::time::Instant::now() < deadline,
"secret write failure acknowledged"
);
}
cx.run_until_sent(|message| {
matches!(message, HostMessage::Ack { id: 644, result: Err(error) } if error.code == "settings_write_failed")
.then_some(())
});
assert_eq!(
std::fs::read_to_string(store.root().join("secrets.json")).unwrap(),
unreadable
Expand Down
Loading