testcontainers
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
export declare const LIB_VERSION = "10.24.0"; | ||
export declare const LIB_VERSION = "10.24.1"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LIB_VERSION = void 0; | ||
exports.LIB_VERSION = "10.24.0"; | ||
exports.LIB_VERSION = "10.24.1"; | ||
//# sourceMappingURL=version.js.map |
@@ -10,2 +10,6 @@ import Dockerode from "dockerode"; | ||
waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>; | ||
handleTimeout(containerId: string): Promise<void>; | ||
handleLogs(container: Dockerode.Container, startTime?: Date): Promise<void>; | ||
matches(line: string): boolean; | ||
throwError(containerId: string, message: string): void; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
const byline_1 = __importDefault(require("byline")); | ||
const promises_1 = require("timers/promises"); | ||
const common_1 = require("../common"); | ||
@@ -21,44 +22,31 @@ const container_runtime_1 = require("../container-runtime"); | ||
async waitUntilReady(container, boundPorts, startTime) { | ||
await Promise.race([this.handleTimeout(container.id), this.handleLogs(container, startTime)]); | ||
} | ||
async handleTimeout(containerId) { | ||
await (0, promises_1.setTimeout)(this.startupTimeout); | ||
this.throwError(containerId, `Log message "${this.message}" not received after ${this.startupTimeout}ms`); | ||
} | ||
async handleLogs(container, startTime) { | ||
common_1.log.debug(`Waiting for log message "${this.message}"...`, { containerId: container.id }); | ||
const client = await (0, container_runtime_1.getContainerRuntimeClient)(); | ||
const stream = await client.container.logs(container, { since: startTime ? startTime.getTime() / 1000 : 0 }); | ||
return new Promise((resolve, reject) => { | ||
const timeout = setTimeout(() => { | ||
const message = `Log message "${this.message}" not received after ${this.startupTimeout}ms`; | ||
common_1.log.error(message, { containerId: container.id }); | ||
reject(new Error(message)); | ||
}, this.startupTimeout); | ||
const comparisonFn = (line) => { | ||
if (this.message instanceof RegExp) { | ||
return this.message.test(line); | ||
let matches = 0; | ||
for await (const line of (0, byline_1.default)(stream)) { | ||
if (this.matches(line)) { | ||
if (++matches === this.times) { | ||
return common_1.log.debug(`Log wait strategy complete`, { containerId: container.id }); | ||
} | ||
else { | ||
return line.includes(this.message); | ||
} | ||
}; | ||
let count = 0; | ||
const lineProcessor = (line) => { | ||
if (comparisonFn(line)) { | ||
if (++count === this.times) { | ||
stream.destroy(); | ||
clearTimeout(timeout); | ||
common_1.log.debug(`Log wait strategy complete`, { containerId: container.id }); | ||
resolve(); | ||
} | ||
} | ||
}; | ||
(0, byline_1.default)(stream) | ||
.on("data", lineProcessor) | ||
.on("err", lineProcessor) | ||
.on("end", () => { | ||
stream.destroy(); | ||
clearTimeout(timeout); | ||
const message = `Log stream ended and message "${this.message}" was not received`; | ||
common_1.log.error(message, { containerId: container.id }); | ||
reject(new Error(message)); | ||
}); | ||
}); | ||
} | ||
} | ||
this.throwError(container.id, `Log stream ended and message "${this.message}" was not received`); | ||
} | ||
matches(line) { | ||
return this.message instanceof RegExp ? this.message.test(line) : line.includes(this.message); | ||
} | ||
throwError(containerId, message) { | ||
common_1.log.error(message, { containerId }); | ||
throw new Error(message); | ||
} | ||
} | ||
exports.LogWaitStrategy = LogWaitStrategy; | ||
//# sourceMappingURL=log-wait-strategy.js.map |
{ | ||
"name": "testcontainers", | ||
"version": "10.24.0", | ||
"version": "10.24.1", | ||
"author": "Cristian Greco", | ||
@@ -40,3 +40,3 @@ "license": "MIT", | ||
"docker-compose": "^0.24.8", | ||
"dockerode": "^4.0.4", | ||
"dockerode": "^4.0.5", | ||
"get-port": "^7.1.0", | ||
@@ -43,0 +43,0 @@ "proper-lockfile": "^4.1.2", |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
386904
-0.13%5468
-0.15%Updated