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
9 changes: 6 additions & 3 deletions src/allow_failure_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "allow_failure ignored" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(allow_failure=true, fn() { raise Err })
Expand All @@ -32,7 +33,8 @@ async test "allow_failure ignored" {

///|
async test "allow_failure waited" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
buf.write_object(
try? @async.with_task_group(fn(root) {
Expand All @@ -47,7 +49,8 @@ async test "allow_failure waited" {

///|
async test "allow_failure no error" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
buf.write_object(
try? @async.with_task_group(fn(root) {
Expand Down
21 changes: 14 additions & 7 deletions src/cancellation_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "manual cancel" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
let result = try? @async.with_task_group(fn(root) {
let task = root.spawn(allow_failure=true, fn() {
Expand Down Expand Up @@ -49,7 +50,8 @@ suberror Err derive(Show)

///|
async test "error propagation" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
let result = try? @async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -85,7 +87,8 @@ async test "error propagation" {

///|
async test "multiple scope" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -151,7 +154,8 @@ async test "multiple scope" {

///|
async test "recursive cancel" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
buf.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -191,7 +195,8 @@ async test "recursive cancel" {

///|
async test "spawn directly error" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
buf.write_object(
try? @async.with_task_group(fn(root) {
Expand All @@ -218,7 +223,8 @@ async test "spawn directly error" {

///|
async test "error in cancellation" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand All @@ -244,7 +250,8 @@ async test "error in cancellation" {

///|
async test "immediately cancelled" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
let task = root.spawn(allow_failure=true, fn() {
Expand Down
1 change: 1 addition & 0 deletions src/fs/walk_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async test "walk sequential" {

///|
async test "walk parallel" {
@async.sleep(300)
let log = StringBuilder::new()
@fs.walk("test_directory", max_concurrency=2, fn(path, _) {
log.write_string("handling \{path}\n")
Expand Down
9 changes: 6 additions & 3 deletions src/group_defer_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "group defer basic" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.add_defer(() => log.write_string("first group defer\n"))
Expand Down Expand Up @@ -55,7 +56,8 @@ async test "group defer basic" {

///|
async test "group defer error" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -98,7 +100,8 @@ async test "group defer error" {

///|
async test "group defer cancelled" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down
6 changes: 4 additions & 2 deletions src/no_wait_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "no_wait cancelled" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(no_wait=true, fn() {
Expand Down Expand Up @@ -42,7 +43,8 @@ async test "no_wait cancelled" {

///|
async test "no_wait normal exit" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let buf = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(no_wait=true, fn() {
Expand Down
27 changes: 18 additions & 9 deletions src/protect_from_cancel_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "protect_from_cancel" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -62,7 +63,8 @@ async test "protect_from_cancel" {

///|
async test "protect_from_cancel wait" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -105,7 +107,8 @@ async test "protect_from_cancel wait" {

///|
async test "protect_from_cancel with_timeout" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -137,7 +140,8 @@ async test "protect_from_cancel with_timeout" {

///|
async test "protect_from_cancel fail" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -169,7 +173,8 @@ async test "protect_from_cancel fail" {

///|
async test "protect_from_cancel nested1" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -203,7 +208,8 @@ async test "protect_from_cancel nested1" {

///|
async test "protect_from_cancel nested2" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -243,7 +249,8 @@ async test "protect_from_cancel nested2" {

///|
async test "protect_from_cancel in cancellation handler" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -276,7 +283,8 @@ async test "protect_from_cancel in cancellation handler" {

///|
async test "cancel while scheduled" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -320,7 +328,8 @@ async test "cancel while scheduled" {

///|
async test "error in async cancel" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down
23 changes: 1 addition & 22 deletions src/random_delay_test.mbt → src/rate_limit_for_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,4 @@
// limitations under the License.

///|
/// add a random delay before every test,
/// so that there won't be a lot of timers expiring at the same time,
/// causing inaccurate result
async fn random_delay() -> Unit {
let rand = match rand_seed.val {
Some(r) => r
None => {
let now = @async.now()
let seed = @buffer.new()
for _ in 0..<4 {
seed.write_int64_le(now)
}
let rand = @random.Rand::chacha8(seed=seed.to_bytes())
rand_seed.val = Some(rand)
rand
}
}
@async.sleep(rand.int(limit=100))
}

///|
let rand_seed : Ref[@random.Rand?] = @ref.new(None)
let rate_limit : @semaphore.Semaphore = @semaphore.Semaphore::new(20)
18 changes: 12 additions & 6 deletions src/retry_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "retry immediate" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
let mut i = 0
@async.retry(Immediate, fn() {
Expand All @@ -37,7 +38,8 @@ async test "retry immediate" {

///|
async test "retry fixed" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
@async.with_task_group(fn(root) {
root.spawn_bg(fn() {
Expand Down Expand Up @@ -72,7 +74,8 @@ async test "retry fixed" {

///|
async test "retry exponential" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -116,7 +119,8 @@ async test "retry exponential" {

///|
async test "retry cancelled1" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
let mut i = 0
@async.with_timeout(500, fn() {
Expand All @@ -142,7 +146,8 @@ async test "retry cancelled1" {

///|
async test "retry cancelled2" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
let mut i = 0
@async.with_timeout(500, fn() {
Expand All @@ -168,7 +173,8 @@ async test "retry cancelled2" {

///|
async test "retry fatal_error" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
fn fatal_error(err) {
not(err is @async.TimeoutError)
Expand Down
9 changes: 6 additions & 3 deletions src/return_immediately_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "return_immediately basic" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand All @@ -33,7 +34,8 @@ async test "return_immediately basic" {

///|
async test "return_immediately nested" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand All @@ -58,7 +60,8 @@ async test "return_immediately nested" {

///|
async test "return_immediately error on cancel" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down
9 changes: 6 additions & 3 deletions src/spawn_loop_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

///|
async test "spawn_loop basic" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -43,7 +44,8 @@ async test "spawn_loop basic" {

///|
async test "spawn_loop basic-error" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down Expand Up @@ -71,7 +73,8 @@ async test "spawn_loop basic-error" {

///|
async test "spawn_loop retry-exponential" {
random_delay()
rate_limit.acquire()
defer rate_limit.release()
let log = StringBuilder::new()
log.write_object(
try? @async.with_task_group(fn(root) {
Expand Down
Loading