Skip to content

Commit

Permalink
chore: better spacing for timer.mo test (#3870)
Browse files Browse the repository at this point in the history
This increases the temporal spacing between output events. The integer seconds cadence _should_ give the same results for all GC schemes.

The schedule is now

| seconds | reaction | `count` |
|----|-----|-----|
| 1.0 | YEP! | 1 |
| 2.0 | DIM! | 2 |
| 3.0 | ROOK! | 3 |
| 4.0 | DIM! | 4 |
| 6.0 | DIM! | 5 |
| 8.0 | BATT! | 6 |
| 13.0 | BATT! | 7 |
| 18.0 | BATT! | 8 |
  • Loading branch information
ggreif authored Mar 11, 2023
1 parent b1f7038 commit f0017cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 2 additions & 4 deletions test/run-drun/ok/timer.drun-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ debug.print: YEP!
debug.print: DIM!
debug.print: ROOK!
debug.print: DIM!
debug.print: DIM!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: {count = 10}
debug.print: {count = 8}
ingress Completed: Reply: 0x4449444c0000
6 changes: 2 additions & 4 deletions test/run-drun/ok/timer.ic-ref-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ debug.print: YEP!
debug.print: DIM!
debug.print: ROOK!
debug.print: DIM!
debug.print: DIM!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: BATT!
debug.print: {count = 10}
debug.print: {count = 8}
<= replied: ()
22 changes: 18 additions & 4 deletions test/run-drun/timer.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@

import { debugPrint; error; setTimer; cancelTimer } = "mo:⛔";

/*
The schedule is
| seconds | reaction |
|----|-----|
| 1.0 | YEP! |
| 2.0 | DIM! |
| 3.0 | ROOK! |
| 4.0 | DIM! |
| 6.0 | DIM! |
| 8.0 | BATT! |
| 13.0 | BATT! |
| 18.0 | BATT! |
*/

actor {

system func timer(setGlobalTimer : Nat64 -> ()) : async () {
await @timer_helper();
};

var count = 0;
var max = 10;
var max = 8;
let raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand;
let second : Nat64 = 1_000_000_000;

public shared func go() : async () {
var attempts = 0;

let id1 = setTimer(1 * second, false, func () : async () { count += 1; debugPrint "YEP!" });
let id2 = setTimer(2 * (second - second / 10), true, func () : async () { count += 1; debugPrint "DIM!" });
let id2 = setTimer(2 * second, true, func () : async () { count += 1; debugPrint "DIM!" });
let id3 = setTimer(3 * second, false, func () : async () {
count += 1;
debugPrint "ROOK!";
ignore setTimer(1 * second, true, func () : async () { count += 1; debugPrint "BATT!" })
ignore setTimer(5 * second, true, func () : async () { count += 1; debugPrint "BATT!" })
});

while (count < max) {
ignore await raw_rand(); // yield to scheduler
attempts += 1;
if (count > 5) { cancelTimer id2 };
if (count >= 5) { cancelTimer id2 };
if (attempts >= 200 and count == 0)
throw error("he's dead Jim");
};
Expand Down

0 comments on commit f0017cc

Please sign in to comment.