Fixing issues dsicovered by automation test cases, as well as disabling threading for test scenarios.
This commit is contained in:
parent
de8a91da83
commit
9f4ff190c3
|
@ -106,6 +106,7 @@ 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)
|
||||||
|
|
||||||
|
try {
|
||||||
const { rows, keys } = await Runner.run({
|
const { rows, keys } = await Runner.run({
|
||||||
datasource,
|
datasource,
|
||||||
queryVerb,
|
queryVerb,
|
||||||
|
@ -117,6 +118,9 @@ exports.preview = async function (ctx) {
|
||||||
rows,
|
rows,
|
||||||
schemaFields: [...new Set(keys)],
|
schemaFields: [...new Set(keys)],
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
ctx.throw(400, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.execute = async function (ctx) {
|
exports.execute = async function (ctx) {
|
||||||
|
@ -131,6 +135,7 @@ exports.execute = async function (ctx) {
|
||||||
)
|
)
|
||||||
|
|
||||||
// call the relevant CRUD method on the integration class
|
// call the relevant CRUD method on the integration class
|
||||||
|
try {
|
||||||
const { rows } = await Runner.run({
|
const { rows } = await Runner.run({
|
||||||
datasource,
|
datasource,
|
||||||
queryVerb: query.queryVerb,
|
queryVerb: query.queryVerb,
|
||||||
|
@ -138,6 +143,9 @@ exports.execute = async function (ctx) {
|
||||||
transformer: query.transformer,
|
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) {
|
||||||
|
|
|
@ -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", () => {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,6 +23,8 @@ function typeToFile(type) {
|
||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
||||||
|
this.type = type
|
||||||
|
if (!env.isTest()) {
|
||||||
const workerOpts = {
|
const workerOpts = {
|
||||||
autoStart: true,
|
autoStart: true,
|
||||||
maxConcurrentWorkers: opts.count ? opts.count : 1,
|
maxConcurrentWorkers: opts.count ? opts.count : 1,
|
||||||
|
@ -31,10 +34,18 @@ class Thread {
|
||||||
}
|
}
|
||||||
this.workers = workerFarm(workerOpts, typeToFile(type))
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue