Files
mongo/jstests/product_limits/libs/workload.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

52 lines
1.6 KiB
JavaScript

import {DEFAULT_SCALE} from "jstests/product_limits/libs/util.js";
export class Workload {
scale() {
return DEFAULT_SCALE;
}
collection() {
return "coll0";
}
check(dataset, actualResult) {
actualResult.sort();
let expectedResult = this.result(dataset);
expectedResult.sort();
print("Comparison start ...");
assert.eq(expectedResult, actualResult);
print("Comparison complete.");
}
result(dataset) {
// By default we assume the workload returns the complete dataset
return dataset.data();
}
}
export class PipelineWorkload extends Workload {
runWorkload(dataset, _, db) {
const coll = db.getCollection(this.collection());
const pipeline = this.pipeline(dataset);
printjsononeline(pipeline);
if (!pipeline[0].hasOwnProperty("$documents")) {
try {
coll.explain("allPlansExecution").aggregate(pipeline);
} catch (error) {
/// Large explains() can not legitimately fit in a BSONObject
printjsononeline(error.codeName);
assert(error.code === ErrorCodes.BSONObjectTooLarge, error);
}
}
const startTime = Date.now();
const cursor = pipeline[0].hasOwnProperty("$documents") ? db.aggregate(pipeline) : coll.aggregate(pipeline);
const actualResult = cursor.toArray();
const duration = Date.now() - startTime;
print(`${dataset.constructor.name}.${this.constructor.name} took ${duration} ms.`);
this.check(dataset, actualResult);
print("Pipeline execution complete.");
}
}