Skip to content

Commit

Permalink
feat: add test stop
Browse files Browse the repository at this point in the history
  • Loading branch information
jincheng.zhang committed Apr 9, 2024
1 parent ff4568b commit cdbab22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
20 changes: 15 additions & 5 deletions crates/netpurr/src/panels/test_editor_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ impl TestEditorPanel {
collection_name: String,
folder: &Rc<RefCell<CollectionFolder>>,
) {
ui.add_enabled_ui(self.run_promise.is_none(), |ui| {
ui.horizontal(|ui|{
ui.checkbox(&mut self.fast,"Parallel Test");
ui.horizontal(|ui|{
ui.checkbox(&mut self.fast,"Parallel Test");
if self.run_promise.is_none() {
if ui.button("Run Test").clicked() {
let test_group_run_result = Arc::new(RwLock::new(TestGroupRunResults::default()));
self.test_group_run_result = Some(test_group_run_result.clone());
Expand All @@ -317,13 +317,23 @@ impl TestEditorPanel {
workspace_data,
operation,
test_group_run_result,
collection_name,
collection_name.clone(),
folder.borrow().get_path(),
self.build_parent_testcase(),
folder.clone(),
);
}
});
}else{
if ui.button("Stop Test").clicked() {
match &self.test_group_run_result {
None => {}
Some(r) => {
r.write().unwrap().stop();
}
}
self.run_promise.take().unwrap().abort();
}
}
});
}

Expand Down
11 changes: 11 additions & 0 deletions crates/netpurr_core/src/runner/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap};
use std::fmt::Debug;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -395,6 +396,9 @@ impl Runner {
}

fn run_one_job(client: Client, test_group_run_result: Arc<RwLock<TestGroupRunResults>>, scope: &Scope, run_request_info: RunRequestInfo) {
if test_group_run_result.read().unwrap().stop_flag{
return;
}
scope.spawn(move |_| {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down Expand Up @@ -526,10 +530,17 @@ impl Runner {
}
#[derive(Default, Clone)]
pub struct TestGroupRunResults {
pub stop_flag:bool,
pub results: HashMap<String, Result<TestRunResult, TestRunError>>,
}

impl TestGroupRunResults {
pub fn stop(&mut self){
self.stop_flag = true;
}
pub fn restart(&mut self){
self.stop_flag = false;
}
pub fn add_result(&mut self, result: Result<TestRunResult, TestRunError>) {
match &result {
Ok(r) => {
Expand Down

0 comments on commit cdbab22

Please sign in to comment.