Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final development version of the devloop. #32

Open
wants to merge 2 commits into
base: assert-devloop-improvements
Choose a base branch
from
Open
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
50 changes: 47 additions & 3 deletions runtime-nodejs/jest.kubernetes-assertions-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const client = require('prom-client');
const register = client.register;
let allow_modification = false;


const assertions_failed = new client.Gauge({
name: 'assertions_failed',
help: 'current numFailingTests incrementally aggregated per run per path',
Expand Down Expand Up @@ -47,6 +48,8 @@ class SpecFilesTracker {

constructor() {
this._pathsSeen = {};
this._pathCounter = {};
this._prevFailTests = 0;
}

pathSeen(path, { numFailingTests }) {
Expand All @@ -58,12 +61,26 @@ class SpecFilesTracker {
}
} else {
this._pathsSeen[path] = {};
this._pathCounter[path] = 0;
assert_files_seen.inc();
if (numFailingTests > 0) assertions_failed.inc(numFailingTests);
console.log('Path reported for the first time:', path);
}

this._pathsSeen[path].numFailingTests = numFailingTests;

if (this._prevFailTests == this._pathsSeen[path].numFailingTests) {
// Tests for path has not increased
this._pathCounter[path]++;
}
this._prevFailTests = this._pathsSeen[path].numFailingTests

console.log("Path: " + path + " times, passed: ", this._pathCounter[path]);

if(this._pathCounter[path] >= 3) {
console.log("Test has passed more than 3 times:", path);
// Remove test from reruns?
}
}

modify(path) {
Expand Down Expand Up @@ -103,10 +120,23 @@ const tracker = new SpecFilesTracker();
* We rerun all tests, not only failed, because when it comes to infra things go up and down.
*/
class Reruns {


timeoutReached() {
console.log("Stopping reruns, timeout has been reached.");
console.log("Will not rerun until file modification");
this._doRerun = false;
// EXIT IMAGE OF DOCKER ASWELL?
}

constructor({ tracker }) {
this._rerunTime = 0;
this._timeout = 0;
this._doRerun = true;
if (fs.existsSync('./env.json')) {
this._rerunTime = Number(JSON.parse(fs.readFileSync('./env.json', 'utf8')).RERUN_TIME);
this._timeout = Number(JSON.parse(fs.readFileSync('./env.json', 'utf8')).TIMEOUT);

}
if (this._rerunTime != 0) {
console.log('Activating reruns with interval (ms)', this._rerunTime * 1000);
Expand All @@ -116,22 +146,36 @@ class Reruns {
setTimeout(() => {
tracker.allowMod();
}, 9000);


if(this._timeout != 0) {
setTimeout(() => {
this.timeoutReached();
}, this._timeout);
}

this._intervalMs = this._rerunTime === 0 ? 10000 : this._rerunTime * 1000;
this._timeout = null;
}

onRunComplete() {
this._timeout !== null && clearTimeout(this._timeout);

if (!ASSERT_IS_DEV && (this._rerunTime > 0)) {

if (!ASSERT_IS_DEV && (this._rerunTime > 0) && this._doRerun) {
console.log("Current reruntime in (s) is: ", this._intervalMs);
this._timeout = setTimeout(() => {
tracker.modifyAll();
}, this._intervalMs);
} else if (assertions_failed.hashMap[''].value > 0) {
// Maybe move the else if to the if above.
} else if (assertions_failed.hashMap[''].value > 0 && this._doRerun) {

this._timeout = setTimeout(() => {
tracker.modifyAll();
}, this._intervalMs);
}
// This is where no reruns should happen?
console.log("Stopping reruns");
}
}

Expand Down Expand Up @@ -225,4 +269,4 @@ class MetricsReporter {
}
}

module.exports = MetricsReporter;
module.exports = MetricsReporter;