From bdc4838b04469d83fb10af65184d7a14fcd39202 Mon Sep 17 00:00:00 2001 From: Johan Fridlund Date: Mon, 3 May 2021 18:35:18 +0200 Subject: [PATCH 01/10] Update jest.kubernetes-assertions-reporter.js --- .../jest.kubernetes-assertions-reporter.js | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/runtime-nodejs/jest.kubernetes-assertions-reporter.js b/runtime-nodejs/jest.kubernetes-assertions-reporter.js index df74a08..b2432cf 100644 --- a/runtime-nodejs/jest.kubernetes-assertions-reporter.js +++ b/runtime-nodejs/jest.kubernetes-assertions-reporter.js @@ -2,11 +2,12 @@ const fs = require('fs'); const http = require('http'); const PORT = process.env.PORT ? parseInt(process.env.PORT) : 9091; -const RERUN_WAIT = parseInt(process.env.RERUN_WAIT); const ASSERT_IS_DEV = process.env.ASSERT_IS_DEV === 'true'; const client = require('prom-client'); const register = client.register; +const rerunTime = process.env.RERUN_TIME || 0; +let hasRun = false; const assertions_failed = new client.Gauge({ name: 'assertions_failed', @@ -52,12 +53,21 @@ class SpecFilesTracker { pathSeen(path, { numFailingTests }) { if (this._pathsSeen.hasOwnProperty(path)) { const delta = numFailingTests - this._pathsSeen[path].numFailingTests; - if (delta > 0) assertions_failed.inc(delta); - if (delta < 0) assertions_failed.dec(-delta); + + console.log(hasRun); + if (hasRun) { + if (delta > 0) assertions_failed.inc(delta); + if (delta < 0) assertions_failed.dec(-delta); + } + } else { this._pathsSeen[path] = {}; assert_files_seen.inc(); - if (numFailingTests > 0) assertions_failed.inc(numFailingTests); + + if (hasRun) { + if (numFailingTests > 0) assertions_failed.inc(numFailingTests); + } + console.log('Path reported for the first time:', path); } this._pathsSeen[path].numFailingTests = numFailingTests; @@ -80,7 +90,6 @@ class SpecFilesTracker { modify(path); }); } - } const tracker = new SpecFilesTracker(); @@ -97,31 +106,38 @@ const tracker = new SpecFilesTracker(); * We rerun all tests, not only failed, because when it comes to infra things go up and down. */ class Reruns { - constructor({ tracker, intervalMs }) { - console.log('Activating reruns with interval (ms)', intervalMs); - this._intervalMs = intervalMs; + this._rerunTime = 0; + if (fs.existsSync('./env.json')) { + this._rerunTime = Number(JSON.parse(fs.readFileSync('./env.json', 'utf8')).RERUN_TIME); + } + if (intervalMs != 0) { + console.log('Activating reruns with interval (ms)', intervalMs); + } else { + console.log('Interval reruns are turned off. Reruns will be run until all tests are OK'); + } + this._intervalMs = this._rerunTime * 1000; this._timeout = null; } onRunComplete() { this._timeout !== null && clearTimeout(this._timeout); - if (!ASSERT_IS_DEV && RERUN_WAIT) { + + if (!ASSERT_IS_DEV && (this._rerunTime > 0 || assertions_failed.hashMap[''].value > 0)) { this._timeout = setTimeout(() => { tracker.modifyAll(); }, this._intervalMs); } } - } + const reruns = new Reruns({ tracker, - intervalMs: RERUN_WAIT * 1000 + intervalMs: 0 * 1000 }); class MetricsServer { - constructor({ port, getMetrics }) { this.port = port; this.getMetrics = getMetrics; @@ -157,7 +173,6 @@ class MetricsServer { stop() { this.server.close(); } - } const server = new MetricsServer({ @@ -167,8 +182,9 @@ const server = new MetricsServer({ server.start(); -class MetricsReporter { + +class MetricsReporter { constructor(globalConfig, options) { this._globalConfig = globalConfig; this._options = options; @@ -179,7 +195,7 @@ class MetricsReporter { onRunStart() { //console.log('onRunStart', arguments); } - + onTestStart() { //console.log('onTestStart', arguments); } @@ -187,22 +203,25 @@ class MetricsReporter { onRunComplete(contexts, results) { //console.log('onRunComplete', contexts, results); const { testResults } = results; + for (let i = 0; i < testResults.length; i++) { const { testFilePath, numFailingTests } = testResults[i]; this._tracker.pathSeen(testFilePath, { numFailingTests }); } + test_suites_run.set(results.numTotalTestSuites); test_suites_run_total.inc(results.numTotalTestSuites); tests_run.set(results.numTotalTests); tests_run_total.inc(results.numTotalTests); assertions_failed_total.inc(results.numFailedTests); + + hasRun = true; if (!this._globalConfig.watch && !this._globalConfig.watchAll) { //console.log('Not a watch run. Exiting'); server.stop(); } reruns.onRunComplete(); } - } module.exports = MetricsReporter; From f5cb1c64d30eaa1f23db02d168f69493ce89e0a0 Mon Sep 17 00:00:00 2001 From: Darclander Date: Mon, 10 May 2021 15:32:57 +0200 Subject: [PATCH 02/10] Update jest.kubernetes-assertions-reporter.js --- .../jest.kubernetes-assertions-reporter.js | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/runtime-nodejs/jest.kubernetes-assertions-reporter.js b/runtime-nodejs/jest.kubernetes-assertions-reporter.js index b2432cf..0a3f75e 100644 --- a/runtime-nodejs/jest.kubernetes-assertions-reporter.js +++ b/runtime-nodejs/jest.kubernetes-assertions-reporter.js @@ -6,8 +6,7 @@ const ASSERT_IS_DEV = process.env.ASSERT_IS_DEV === 'true'; const client = require('prom-client'); const register = client.register; -const rerunTime = process.env.RERUN_TIME || 0; -let hasRun = false; +let allow_modification = false; const assertions_failed = new client.Gauge({ name: 'assertions_failed', @@ -53,23 +52,17 @@ class SpecFilesTracker { pathSeen(path, { numFailingTests }) { if (this._pathsSeen.hasOwnProperty(path)) { const delta = numFailingTests - this._pathsSeen[path].numFailingTests; - - console.log(hasRun); - if (hasRun) { + if(allow_modification) { if (delta > 0) assertions_failed.inc(delta); if (delta < 0) assertions_failed.dec(-delta); } - } else { this._pathsSeen[path] = {}; assert_files_seen.inc(); - - if (hasRun) { - if (numFailingTests > 0) assertions_failed.inc(numFailingTests); - } - + if (numFailingTests > 0) assertions_failed.inc(numFailingTests); console.log('Path reported for the first time:', path); } + this._pathsSeen[path].numFailingTests = numFailingTests; } @@ -81,6 +74,10 @@ class SpecFilesTracker { }); } + allowMod() { + allow_modification = true; + } + modifyAll() { const modify = this.modify.bind(this); const paths = Object.keys(this._pathsSeen); @@ -106,24 +103,31 @@ const tracker = new SpecFilesTracker(); * We rerun all tests, not only failed, because when it comes to infra things go up and down. */ class Reruns { - constructor({ tracker, intervalMs }) { + constructor({ tracker }) { this._rerunTime = 0; if (fs.existsSync('./env.json')) { this._rerunTime = Number(JSON.parse(fs.readFileSync('./env.json', 'utf8')).RERUN_TIME); } - if (intervalMs != 0) { - console.log('Activating reruns with interval (ms)', intervalMs); + if (this._rerunTime != 0) { + console.log('Activating reruns with interval (ms)', this._rerunTime * 1000); } else { console.log('Interval reruns are turned off. Reruns will be run until all tests are OK'); } - this._intervalMs = this._rerunTime * 1000; + setTimeout(() => { + tracker.allowMod(); + }, 9000); + 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 || assertions_failed.hashMap[''].value > 0)) { + if (!ASSERT_IS_DEV && (this._rerunTime > 0)) { + this._timeout = setTimeout(() => { + tracker.modifyAll(); + }, this._intervalMs); + } else if (assertions_failed.hashMap[''].value > 0) { this._timeout = setTimeout(() => { tracker.modifyAll(); }, this._intervalMs); @@ -131,10 +135,8 @@ class Reruns { } } - const reruns = new Reruns({ - tracker, - intervalMs: 0 * 1000 + tracker }); class MetricsServer { @@ -215,7 +217,6 @@ class MetricsReporter { tests_run_total.inc(results.numTotalTests); assertions_failed_total.inc(results.numFailedTests); - hasRun = true; if (!this._globalConfig.watch && !this._globalConfig.watchAll) { //console.log('Not a watch run. Exiting'); server.stop(); From c97c3bd2ca0b7e4eccc947d53c2f7ff3eeb03f74 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 12:45:06 +0200 Subject: [PATCH 03/10] We currently have no use for specs images outside skaffold runs --- hooks/build | 1 - 1 file changed, 1 deletion(-) diff --git a/hooks/build b/hooks/build index 0a7d85b..7d8025c 100755 --- a/hooks/build +++ b/hooks/build @@ -26,7 +26,6 @@ docker build -t $IMAGE_NAME . CONTEXTS=" runtime-nodejs runtime-typescript -specs " PUSH="" From 136c2bf65c6ddfba00361794a78031c58c0ea214 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 12:52:42 +0200 Subject: [PATCH 04/10] For dev loops involving a runtime we need [git rev][-dirty?] tags with builds-registry URLs --- README.md | 3 ++- hooks/build | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d02e59a..44f2358 100644 --- a/README.md +++ b/README.md @@ -106,12 +106,13 @@ docker-compose -f docker-compose.test.yml up --no-build kubernetes-mixin Build only: ``` -NOPUSH=true IMAGE_NAME=solsson/kubernetes-assert:latest ./hooks/build +NOPUSH=true IMAGE_NAME=builds-registry.ystack.svc.cluster.local/yolean/assert ./hooks/build ``` Integration test: ``` +NOPUSH=true IMAGE_NAME=solsson/kubernetes-assert:latest ./hooks/build docker volume rm kubernetes-monitoring_admin 2> /dev/null || true ./test.sh ``` diff --git a/hooks/build b/hooks/build index 7d8025c..980ada2 100755 --- a/hooks/build +++ b/hooks/build @@ -2,6 +2,10 @@ [ -z "$DEBUG" ] || set -x set -eo pipefail +# Settings +DEFAULT_REGISTRY=builds-registry.ystack.svc.cluster.local +[ -z "$BUILDS_REGISTRY" ] && BUILDS_REGISTRY=$DEFAULT_REGISTRY + [ -z "$IMAGE_NAME" ] && echo "IMAGE_NAME is required" && exit 1; GIT_STATUS=$(git status --untracked-files=no --porcelain=v2) @@ -12,6 +16,13 @@ GIT_STATUS=$(git status --untracked-files=no --porcelain=v2) echo "------ HOOK START - BUILD -------" printenv +PREPEND_REGISTRY="" +case $IMAGE_NAME in + solsson/* ) ;; + $BUILDS_REGISTRY* ) PREPEND_REGISTRY="${BUILDS_REGISTRY}/" ;; + *) ;; +esac + function imagename { buildname=$1 case $IMAGE_NAME in @@ -34,8 +45,8 @@ for CONTEXT in $CONTEXTS; do CONTEXT_IMAGE_NAME=$(imagename $CONTEXT) - docker build -t $CONTEXT_IMAGE_NAME -t yolean/assert-$CONTEXT -t yolean/assert-$CONTEXT:$SOURCE_COMMIT ./$CONTEXT - PUSH="$PUSH $CONTEXT_IMAGE_NAME yolean/assert-$CONTEXT:$SOURCE_COMMIT" + docker build -t $CONTEXT_IMAGE_NAME -t yolean/assert-$CONTEXT -t ${PREPEND_REGISTRY}yolean/assert-$CONTEXT:$SOURCE_COMMIT ./$CONTEXT + PUSH="$PUSH $CONTEXT_IMAGE_NAME ${PREPEND_REGISTRY}yolean/assert-$CONTEXT:$SOURCE_COMMIT" done From 6586929ced36504648b88244b7f085f238ff23e2 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 13:11:49 +0200 Subject: [PATCH 05/10] Was misleading to have a dockerfile while relying on y-build-like-sync --- specs/Dockerfile | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 specs/Dockerfile diff --git a/specs/Dockerfile b/specs/Dockerfile deleted file mode 100644 index c9140c3..0000000 --- a/specs/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM yolean/assert-runtime-nodejs - -WORKDIR /usr/src/specs - -# When we add dependencies -#COPY --chown=nonroot:nogroup package*.json ./ -#RUN npm ci --ignore-scripts - -COPY --chown=nonroot:nogroup . . From b50c145814485c31d7639851a2a3734f7f25cc7b Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 14:17:45 +0200 Subject: [PATCH 06/10] As #19 documents this env no longer works so let's look for alternative appoaches, starting with #26 --- runtime-nodejs/kustomize/scrapeable-deployment.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/runtime-nodejs/kustomize/scrapeable-deployment.yaml b/runtime-nodejs/kustomize/scrapeable-deployment.yaml index 496a334..f01139e 100644 --- a/runtime-nodejs/kustomize/scrapeable-deployment.yaml +++ b/runtime-nodejs/kustomize/scrapeable-deployment.yaml @@ -38,11 +38,6 @@ spec: valueFrom: fieldRef: fieldPath: spec.serviceAccountName - - name: ASSERT_IS_DEV - valueFrom: - fieldRef: - # This will be true for run --tail as well but that's also a dev-loop use case - fieldPath: metadata.labels['skaffold.dev/tail'] ports: - containerPort: 9091 name: assert From abc1f6390b96a5eda53bbcbee6037f5a98ecc25a Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 14:20:33 +0200 Subject: [PATCH 07/10] Makes use of Yolean/ystack#39 so we can iterate on runtime+specs --- specs/skaffold.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/specs/skaffold.yaml b/specs/skaffold.yaml index 8372f5c..2681b25 100644 --- a/specs/skaffold.yaml +++ b/specs/skaffold.yaml @@ -1,4 +1,4 @@ -apiVersion: skaffold/v2beta4 +apiVersion: skaffold/v2beta15 kind: Config metadata: name: assert-specs @@ -7,13 +7,16 @@ build: gitCommit: variant: CommitSha artifacts: - - image: builds-registry.ystack.svc.cluster.local:80/yolean/assert-specs + - image: builds-registry.ystack.svc.cluster.local/yolean/assert-specs + context: ./ + custom: + buildCommand: >- + y-build-like-sync + builds-registry.ystack.svc.cluster.local/yolean/assert-runtime-nodejs:../../kubernetes-assert/runtime-nodejs sync: manual: - src: '**' dest: /usr/src/specs - kaniko: - reproducible: true cluster: {} deploy: kustomize: {} From 51c5bdbff4e1c7f5962688182aaba1c95e45b613 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Tue, 11 May 2021 14:53:52 +0200 Subject: [PATCH 08/10] Moves RBAC resources to a dedicated base, so specs that don't need rbac can be created and deleted faster. Specs might not use the kubernetes client, or mighte have sufficient access with the default service account such as in ephemeral test clusters. --- runtime-nodejs/kustomize-with-rbac/kustomization.yaml | 7 +++++++ .../kustomize-with-rbac/specs-serviceaccount.yaml | 8 ++++++++ runtime-nodejs/kustomize/kustomization.yaml | 2 -- runtime-nodejs/kustomize/scrapeable-deployment.yaml | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 runtime-nodejs/kustomize-with-rbac/kustomization.yaml create mode 100644 runtime-nodejs/kustomize-with-rbac/specs-serviceaccount.yaml diff --git a/runtime-nodejs/kustomize-with-rbac/kustomization.yaml b/runtime-nodejs/kustomize-with-rbac/kustomization.yaml new file mode 100644 index 0000000..bc6a33e --- /dev/null +++ b/runtime-nodejs/kustomize-with-rbac/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +bases: +- ../rbac-readonly +- ../kustomize +patchesStrategicMerge: +- specs-serviceaccount.yaml diff --git a/runtime-nodejs/kustomize-with-rbac/specs-serviceaccount.yaml b/runtime-nodejs/kustomize-with-rbac/specs-serviceaccount.yaml new file mode 100644 index 0000000..55952d1 --- /dev/null +++ b/runtime-nodejs/kustomize-with-rbac/specs-serviceaccount.yaml @@ -0,0 +1,8 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: specs +spec: + template: + spec: + serviceAccountName: assert diff --git a/runtime-nodejs/kustomize/kustomization.yaml b/runtime-nodejs/kustomize/kustomization.yaml index a6162d1..d3e8f9f 100644 --- a/runtime-nodejs/kustomize/kustomization.yaml +++ b/runtime-nodejs/kustomize/kustomization.yaml @@ -1,7 +1,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -bases: -- ../rbac-readonly resources: - scrapeable-deployment.yaml # TODO if many tests reuse this base, how do we manage podmonitor? diff --git a/runtime-nodejs/kustomize/scrapeable-deployment.yaml b/runtime-nodejs/kustomize/scrapeable-deployment.yaml index f01139e..6878aba 100644 --- a/runtime-nodejs/kustomize/scrapeable-deployment.yaml +++ b/runtime-nodejs/kustomize/scrapeable-deployment.yaml @@ -12,7 +12,6 @@ spec: labels: kubernetes-assert: metrics spec: - serviceAccountName: assert containers: - name: specs # We can't have a tag here because https://kubectl.docs.kubernetes.io/pages/reference/kustomize.html#images won't unset it, and Skaffold required no-tag URLs for build From 66e447a4357c831e9dc7693e641c5e4f51aba20e Mon Sep 17 00:00:00 2001 From: Darclander Date: Mon, 24 May 2021 23:21:41 +0200 Subject: [PATCH 09/10] Timeout and delay Timeout and delay should now be implemented for the cluster. Have not had enough time to see if it works properly. The logic should be there though. The image is not exited but there is a condition for where it should. --- .../jest.kubernetes-assertions-reporter.js | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/runtime-nodejs/jest.kubernetes-assertions-reporter.js b/runtime-nodejs/jest.kubernetes-assertions-reporter.js index df74a08..3dfb618 100644 --- a/runtime-nodejs/jest.kubernetes-assertions-reporter.js +++ b/runtime-nodejs/jest.kubernetes-assertions-reporter.js @@ -8,6 +8,7 @@ const ASSERT_IS_DEV = process.env.ASSERT_IS_DEV === 'true'; const client = require('prom-client'); const register = client.register; + const assertions_failed = new client.Gauge({ name: 'assertions_failed', help: 'current numFailingTests incrementally aggregated per run per path', @@ -47,6 +48,8 @@ class SpecFilesTracker { constructor() { this._pathsSeen = {}; + this._pathCounter = {}; + this._prevFailTests = 0; } pathSeen(path, { numFailingTests }) { @@ -56,11 +59,25 @@ class SpecFilesTracker { if (delta < 0) assertions_failed.dec(-delta); } 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) { @@ -71,6 +88,11 @@ class SpecFilesTracker { }); } + allowMod() { + allow_modification = true; + console.log("Allow modifications: ", allow_modification); + } + modifyAll() { const modify = this.modify.bind(this); const paths = Object.keys(this._pathsSeen); @@ -98,19 +120,57 @@ const tracker = new SpecFilesTracker(); */ class Reruns { - constructor({ tracker, intervalMs }) { - console.log('Activating reruns with interval (ms)', intervalMs); - this._intervalMs = intervalMs; + 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); + } else { + console.log('Interval reruns are turned off. Reruns will be run until all tests are OK'); + } + 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 && RERUN_WAIT) { + + 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); + // 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"); } } From fd7189e572dc7a878707a7e5ba8c6d705cff5da9 Mon Sep 17 00:00:00 2001 From: Darclander Date: Tue, 25 May 2021 14:13:31 +0200 Subject: [PATCH 10/10] Revert "Timeout and delay" This reverts commit 66e447a4357c831e9dc7693e641c5e4f51aba20e. --- .../jest.kubernetes-assertions-reporter.js | 68 ++----------------- 1 file changed, 4 insertions(+), 64 deletions(-) diff --git a/runtime-nodejs/jest.kubernetes-assertions-reporter.js b/runtime-nodejs/jest.kubernetes-assertions-reporter.js index 3dfb618..df74a08 100644 --- a/runtime-nodejs/jest.kubernetes-assertions-reporter.js +++ b/runtime-nodejs/jest.kubernetes-assertions-reporter.js @@ -8,7 +8,6 @@ const ASSERT_IS_DEV = process.env.ASSERT_IS_DEV === 'true'; const client = require('prom-client'); const register = client.register; - const assertions_failed = new client.Gauge({ name: 'assertions_failed', help: 'current numFailingTests incrementally aggregated per run per path', @@ -48,8 +47,6 @@ class SpecFilesTracker { constructor() { this._pathsSeen = {}; - this._pathCounter = {}; - this._prevFailTests = 0; } pathSeen(path, { numFailingTests }) { @@ -59,25 +56,11 @@ class SpecFilesTracker { if (delta < 0) assertions_failed.dec(-delta); } 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) { @@ -88,11 +71,6 @@ class SpecFilesTracker { }); } - allowMod() { - allow_modification = true; - console.log("Allow modifications: ", allow_modification); - } - modifyAll() { const modify = this.modify.bind(this); const paths = Object.keys(this._pathsSeen); @@ -120,57 +98,19 @@ const tracker = new SpecFilesTracker(); */ 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); - } else { - console.log('Interval reruns are turned off. Reruns will be run until all tests are OK'); - } - setTimeout(() => { - tracker.allowMod(); - }, 9000); - - if(this._timeout != 0) { - setTimeout(() => { - this.timeoutReached(); - }, this._timeout); - } - - - this._intervalMs = this._rerunTime === 0 ? 10000 : this._rerunTime * 1000; + constructor({ tracker, intervalMs }) { + console.log('Activating reruns with interval (ms)', intervalMs); + this._intervalMs = intervalMs; this._timeout = null; } onRunComplete() { this._timeout !== null && clearTimeout(this._timeout); - - 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); - // Maybe move the else if to the if above. - } else if (assertions_failed.hashMap[''].value > 0 && this._doRerun) { + if (!ASSERT_IS_DEV && RERUN_WAIT) { this._timeout = setTimeout(() => { tracker.modifyAll(); }, this._intervalMs); } - // This is where no reruns should happen? - console.log("Stopping reruns"); } }