Skip to content

Commit

Permalink
优化了Atom
Browse files Browse the repository at this point in the history
  • Loading branch information
zuon committed Jun 6, 2018
1 parent 170dcf3 commit 6e27926
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn native_object_call_test() {
copy.call(3);
}

// #[test]
#[test]
fn native_object_call_block_reply_test() {
let worker_pool = Box::new(WorkerPool::new(3, 1024 * 1024, 1000));
worker_pool.run(JS_TASK_POOL.clone());
Expand All @@ -323,7 +323,7 @@ fn native_object_call_block_reply_test() {
let result = |vm: Arc<JS>| {
vm.new_str("Hello World0".to_string());
};
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, "block reply task0");
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task0"));
while !arc.is_ran() {
thread::sleep(Duration::from_millis(1));
}
Expand All @@ -347,27 +347,27 @@ fn native_object_call_block_reply_test() {
arc1.new_str("你好 World!!!!!!".to_string());
arc1.call(3);
});
cast_task(task_type, priority, func, "call block task");
cast_task(task_type, priority, func, Atom::from("call block task"));
thread::sleep(Duration::from_millis(500)); //保证同步任务先执行

let result = |vm: Arc<JS>| {
vm.new_str("Hello World1".to_string());
};
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, "block reply task1");
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task1"));
thread::sleep(Duration::from_millis(500));

let result = |vm: Arc<JS>| {
vm.new_str("Hello World2".to_string());
};
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, "block reply task2");
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task2"));
thread::sleep(Duration::from_millis(500));

let result = |vm: Arc<JS>| {
vm.new_str("Hello World3".to_string());
};
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, "block reply task3");
block_reply(arc.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task3"));

block_throw(arc.clone(), "Throw Error".to_string(), TaskType::Sync, 10, "block throw task");
block_throw(arc.clone(), "Throw Error".to_string(), TaskType::Sync, 10, Atom::from("block throw task"));
thread::sleep(Duration::from_millis(1000));
}

Expand All @@ -387,7 +387,7 @@ fn native_object_call_block_reply_test_by_clone() {
let result = |vm: Arc<JS>| {
vm.new_str("Hello World0".to_string());
};
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, "block reply task0");
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task0"));
while !copy.is_ran() {
thread::sleep(Duration::from_millis(1));
}
Expand All @@ -403,27 +403,27 @@ fn native_object_call_block_reply_test_by_clone() {
copy1.new_str("你好 World!!!!!!".to_string());
copy1.call(3);
});
cast_task(task_type, priority, func, "call block task");
cast_task(task_type, priority, func, Atom::from("call block task"));
thread::sleep(Duration::from_millis(500)); //保证同步任务先执行

let result = |vm: Arc<JS>| {
vm.new_str("Hello World1".to_string());
};
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, "block reply task1");
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task1"));
thread::sleep(Duration::from_millis(500));

let result = |vm: Arc<JS>| {
vm.new_str("Hello World2".to_string());
};
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, "block reply task2");
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task2"));
thread::sleep(Duration::from_millis(500));

let result = |vm: Arc<JS>| {
vm.new_str("Hello World3".to_string());
};
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, "block reply task3");
block_reply(copy.clone(), Box::new(result), TaskType::Sync, 10, Atom::from("block reply task3"));

block_throw(copy.clone(), "Throw Error".to_string(), TaskType::Sync, 10, "block throw task");
block_throw(copy.clone(), "Throw Error".to_string(), TaskType::Sync, 10, Atom::from("block throw task"));
thread::sleep(Duration::from_millis(1000));
}

Expand Down Expand Up @@ -462,10 +462,10 @@ fn task_test() {
copy.call(3);
thread::sleep(Duration::from_millis(1000)); //延迟结束任务
});
cast_task(task_type, priority, func, "first task");
cast_task(task_type, priority, func, Atom::from("first task"));
thread::sleep(Duration::from_millis(1000)); //延迟结束任务
});
cast_task(task_type, priority, func, "second task");
cast_task(task_type, priority, func, Atom::from("second task"));
println!("worker_pool: {}", worker_pool);
//测试运行任务的同时增加工作者
for index in 0..10 {
Expand All @@ -478,7 +478,7 @@ fn task_test() {
copy.new_str("Hello World!!!!!!".to_string());
copy.call(3);
thread::sleep(Duration::from_millis(1000)); //延迟结束任务
}), "other task");
}), Atom::from("other task"));
}
worker_pool.increase(JS_TASK_POOL.clone(), 7, 1000);
thread::sleep(Duration::from_millis(10000));
Expand All @@ -494,14 +494,14 @@ fn task_test() {
copy.new_str("Hello World!!!!!!".to_string());
copy.call(3);
thread::sleep(Duration::from_millis(1000)); //延迟结束任务
}), "other task");
}), Atom::from("other task"));
}
worker_pool.decrease(7);
thread::sleep(Duration::from_millis(10000));
println!("worker_pool: {}", worker_pool);
}

#[test]
// #[test]
fn test_vm_factory() {
let worker_pool = Box::new(WorkerPool::new(3, 1024 * 1024, 1000));
worker_pool.run(JS_TASK_POOL.clone());
Expand All @@ -518,7 +518,7 @@ fn test_vm_factory() {

let factory = VMFactory::new(0);
assert!(factory.size() == 0);
factory.append(Arc::new(code))
.call(1, Atom::from("Hello World"), Arc::new(vec![100, 100, 100, 100, 100, 100]), "factory call");
// factory.append(Arc::new(code))
// .call(1, Atom::from("Hello World"), Arc::new(vec![100, 100, 100, 100, 100, 100]), "factory call");
thread::sleep(Duration::from_millis(1000));
}

0 comments on commit 6e27926

Please sign in to comment.