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,6 +106,7 @@ exports.preview = async function (ctx) {
|
|||
const { fields, parameters, queryVerb, transformer } = ctx.request.body
|
||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||
|
||||
try {
|
||||
const { rows, keys } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb,
|
||||
|
@ -117,6 +118,9 @@ exports.preview = async function (ctx) {
|
|||
rows,
|
||||
schemaFields: [...new Set(keys)],
|
||||
}
|
||||
} catch (err) {
|
||||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
||||
exports.execute = async function (ctx) {
|
||||
|
@ -131,6 +135,7 @@ exports.execute = async function (ctx) {
|
|||
)
|
||||
|
||||
// call the relevant CRUD method on the integration class
|
||||
try {
|
||||
const { rows } = await Runner.run({
|
||||
datasource,
|
||||
queryVerb: query.queryVerb,
|
||||
|
@ -138,6 +143,9 @@ exports.execute = async function (ctx) {
|
|||
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,6 +23,8 @@ function typeToFile(type) {
|
|||
|
||||
class Thread {
|
||||
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
||||
this.type = type
|
||||
if (!env.isTest()) {
|
||||
const workerOpts = {
|
||||
autoStart: true,
|
||||
maxConcurrentWorkers: opts.count ? opts.count : 1,
|
||||
|
@ -31,10 +34,18 @@ class Thread {
|
|||
}
|
||||
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