@lifeomic/double-check
v1.1.4
Published
This package provides a utility for comparing the behavior of two function invocations in parallel, using different arguments.
Downloads
66
Readme
This package provides a utility for comparing the behavior of two function invocations in parallel, using different arguments.
It's especially useful for exercising the behavior of a certain block of code in a blue-green scenario, and comparing the results between a primary + secondary configuration.
Installation
yarn add @lifeomic/double-check
Usage
import { compare } from '@lifeomic/double-check';
const response = await compare({
configurations: {
// Specify a primary configuration.
primary: {
databaseClient: primaryDatabaseClient,
},
// Specify an optional secondary configuration.
secondary: {
databaseClient: secondaryDatabaseClient,
},
},
// Specify the operation you'd like to perform using the configuration.
operation: ({ databaseClient }) => {
return databaseClient.query('SELECT * FROM users');
},
// Specify a secondary timeout.
cutoffSecondaryAfterMs: 300,
});
// The response contains:
// The primary result.
response.primaryResult;
// A comparison of the results, if a secondary configuration was specified.
//
// This report should be logged and examined over time to analyze similarity between
// the primary + secondary configurations.
response.report;
// The error from the secondary operation, if it failed.
response.secondaryError;