1
0
Fork 0
mirror of synced 2024-09-28 07:11:40 +12:00

Fixing issues dsicovered by automation test cases, as well as disabling threading for test scenarios.

This commit is contained in:
mike12345567 2021-11-11 16:20:30 +00:00
parent f5e2e2baca
commit 2dee1d6cff
4 changed files with 47 additions and 27 deletions

View file

@ -106,16 +106,20 @@ exports.preview = async function (ctx) {
const { fields, parameters, queryVerb, transformer } = ctx.request.body const { fields, parameters, queryVerb, transformer } = ctx.request.body
const enrichedQuery = await enrichQueryFields(fields, parameters) const enrichedQuery = await enrichQueryFields(fields, parameters)
const { rows, keys } = await Runner.run({ try {
datasource, const { rows, keys } = await Runner.run({
queryVerb, datasource,
query: enrichedQuery, queryVerb,
transformer, query: enrichedQuery,
}) transformer,
})
ctx.body = { ctx.body = {
rows, rows,
schemaFields: [...new Set(keys)], schemaFields: [...new Set(keys)],
}
} catch (err) {
ctx.throw(400, err)
} }
} }
@ -131,13 +135,17 @@ exports.execute = async function (ctx) {
) )
// call the relevant CRUD method on the integration class // call the relevant CRUD method on the integration class
const { rows } = await Runner.run({ try {
datasource, const { rows } = await Runner.run({
queryVerb: query.queryVerb, datasource,
query: enrichedQuery, queryVerb: query.queryVerb,
transformer: query.transformer, query: enrichedQuery,
}) transformer: query.transformer,
ctx.body = rows })
ctx.body = rows
} catch (err) {
ctx.throw(400, err)
}
} }
exports.destroy = async function (ctx) { exports.destroy = async function (ctx) {

View file

@ -1,5 +1,5 @@
jest.mock("../../utilities/usageQuota") jest.mock("../../utilities/usageQuota")
jest.mock("../thread") jest.mock("../../threads/automation")
jest.mock("../../utilities/redis", () => ({ jest.mock("../../utilities/redis", () => ({
init: jest.fn(), init: jest.fn(),
checkTestFlag: () => { checkTestFlag: () => {
@ -53,7 +53,7 @@ describe("Run through some parts of the automations system", () => {
} }
}) })
await wait(100) await wait(100)
expect().toHaveBeenCalledWith(makePartial({ expect(thread).toHaveBeenCalledWith(makePartial({
data: { data: {
event: { event: {
fields: { fields: {
@ -61,7 +61,7 @@ describe("Run through some parts of the automations system", () => {
} }
} }
} }
})) }), expect.any(Function))
}) })
it("should be able to clean inputs with the utilities", () => { it("should be able to clean inputs with the utilities", () => {

View file

@ -33,6 +33,7 @@ function parse(input: any) {
if (isIsoDateString(input)) { if (isIsoDateString(input)) {
return new Date(input) return new Date(input)
} }
return input
} }
function parseBody(body: any) { function parseBody(body: any) {

View file

@ -1,4 +1,5 @@
const workerFarm = require("worker-farm") const workerFarm = require("worker-farm")
const env = require("../environment")
const ThreadType = { const ThreadType = {
QUERY: "query", QUERY: "query",
@ -22,19 +23,29 @@ function typeToFile(type) {
class Thread { class Thread {
constructor(type, opts = { timeoutMs: null, count: 1 }) { constructor(type, opts = { timeoutMs: null, count: 1 }) {
const workerOpts = { this.type = type
autoStart: true, if (!env.isTest()) {
maxConcurrentWorkers: opts.count ? opts.count : 1, const workerOpts = {
autoStart: true,
maxConcurrentWorkers: opts.count ? opts.count : 1,
}
if (opts.timeoutMs) {
workerOpts.maxCallTime = opts.timeoutMs
}
this.workers = workerFarm(workerOpts, typeToFile(type))
} }
if (opts.timeoutMs) {
workerOpts.maxCallTime = opts.timeoutMs
}
this.workers = workerFarm(workerOpts, typeToFile(type))
} }
run(data) { run(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.workers(data, (err, response) => { let fncToCall
// if in test then don't use threading
if (env.isTest()) {
fncToCall = require(typeToFile(this.type))
} else {
fncToCall = this.workers
}
fncToCall(data, (err, response) => {
if (err) { if (err) {
reject(err) reject(err)
} else { } else {