Fixing issues dsicovered by automation test cases, as well as disabling threading for test scenarios.
This commit is contained in:
parent
f5e2e2baca
commit
2dee1d6cff
|
@ -106,16 +106,20 @@ exports.preview = async function (ctx) {
|
|||
const { fields, parameters, queryVerb, transformer } = ctx.request.body
|
||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||
|
||||
const { rows, keys } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb,
|
||||
query: enrichedQuery,
|
||||
transformer,
|
||||
})
|
||||
try {
|
||||
const { rows, keys } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb,
|
||||
query: enrichedQuery,
|
||||
transformer,
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
rows,
|
||||
schemaFields: [...new Set(keys)],
|
||||
ctx.body = {
|
||||
rows,
|
||||
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
|
||||
const { rows } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb: query.queryVerb,
|
||||
query: enrichedQuery,
|
||||
transformer: query.transformer,
|
||||
})
|
||||
ctx.body = rows
|
||||
try {
|
||||
const { rows } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb: query.queryVerb,
|
||||
query: enrichedQuery,
|
||||
transformer: query.transformer,
|
||||
})
|
||||
ctx.body = rows
|
||||
} catch (err) {
|
||||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
||||
exports.destroy = async function (ctx) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
jest.mock("../../utilities/usageQuota")
|
||||
jest.mock("../thread")
|
||||
jest.mock("../../threads/automation")
|
||||
jest.mock("../../utilities/redis", () => ({
|
||||
init: jest.fn(),
|
||||
checkTestFlag: () => {
|
||||
|
@ -53,7 +53,7 @@ describe("Run through some parts of the automations system", () => {
|
|||
}
|
||||
})
|
||||
await wait(100)
|
||||
expect().toHaveBeenCalledWith(makePartial({
|
||||
expect(thread).toHaveBeenCalledWith(makePartial({
|
||||
data: {
|
||||
event: {
|
||||
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", () => {
|
||||
|
|
|
@ -33,6 +33,7 @@ function parse(input: any) {
|
|||
if (isIsoDateString(input)) {
|
||||
return new Date(input)
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
function parseBody(body: any) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const workerFarm = require("worker-farm")
|
||||
const env = require("../environment")
|
||||
|
||||
const ThreadType = {
|
||||
QUERY: "query",
|
||||
|
@ -22,19 +23,29 @@ function typeToFile(type) {
|
|||
|
||||
class Thread {
|
||||
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
||||
const workerOpts = {
|
||||
autoStart: true,
|
||||
maxConcurrentWorkers: opts.count ? opts.count : 1,
|
||||
this.type = type
|
||||
if (!env.isTest()) {
|
||||
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) {
|
||||
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) {
|
||||
reject(err)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue