Skip to content

Commit

Permalink
very rudimentary mechanism for inducing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
aslanix committed Feb 12, 2024
1 parent beb3825 commit f6de39f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
4 changes: 4 additions & 0 deletions _new_tests/failure_check.trp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let fun loop i = print i ; loop (i + 1)
val p = spawn (fn () => _setFailureRate (1/200); loop 0)
in ()
end
19 changes: 18 additions & 1 deletion rt/src/Scheduler.mts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Scheduler implements SchedulerInterface {
2018-02-18: AA: a hypothesis about memory management in V8
It appears that V8's memory management is not very well suited for infinitely
It appears tht V8's memory management is not very well suited for infinitely
running functions. In other words, functions are expected to eventually
terminate, and all long-running computations are expected to run through the
event loop. This is not surprising given the application where V8 is used.
Expand Down Expand Up @@ -281,6 +281,23 @@ export class Scheduler implements SchedulerInterface {
// if (dest.debugname ) {
// console.log (" -- ", dest.debugname)
// }
if (this.__currentThread.failureRate > 0 ) {
if (this.__currentThread.failureStartTime > 0) {
if (Date.now() > this.__currentThread.failureStartTime ) {
this.__currentThread.failureStartTime = 0
}
} else {
let liveOrDie = Math.random ()
// console.log (liveOrDie, this.__currentThread.failureRate )
if (liveOrDie < this.__currentThread.failureRate) {
console.log ("INDUCING FAILURE")
dest = null;
this.done( ); ;; // 2024-02-12; AA ; ugly hack.
break;
}
}
}

dest = dest ()
}

Expand Down
35 changes: 20 additions & 15 deletions rt/src/builtins/debugutils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ export function BuiltinDebugUtils <TBase extends Constructor<UserRuntimeZero>> (

_setFailureRate = mkBase((arg) => {
let _tt = arg.getTroupeType;
switch (_tt) {
case TroupeType.NUMBER:
this.runtime.$t.failureRate = arg.val
this.runtime.$t.failureStartTime = 0;
break;
case TroupeType.TUPLE:
assertIsNTuple(arg, 2)
assertIsNumber (arg.val[0])
assertIsNumber (arg.val[1])
this.runtime.$t.failureRate = arg.val[0].val
this.runtime.$t.failureStartTime = Date.now() + arg.val[1].val
break;
default:
this.runtime.$t.threadError ("Invalid argument type in function _setFailureRate");
}
assertIsNumber(arg);
this.runtime.$t.failureRate = arg.val ;
// return this.runtime.ret(new LVal(Math.ceil(arg.val), arg.lev, arg.tlev));

// switch (_tt) {
// case TroupeType.NUMBER:
// this.runtime.$t.failureRate = arg.val
// this.runtime.$t.failureStartTime = 0;
// break;
// case TroupeType.TUPLE:
// assertIsNTuple(arg, 2)
// assertIsNumber (arg.val[0])
// assertIsNumber (arg.val[1])
// this.runtime.$t.failureRate = arg.val[0].val
// this.runtime.$t.failureStartTime = Date.now() + arg.val[1].val
// break;
// default:
// this.runtime.$t.threadError ("Invalid argument type in function _setFailureRate");
// }

return this.runtime.ret(__unit);
})
}
Expand Down

0 comments on commit f6de39f

Please sign in to comment.