Updating backend tests to actually utilise the redis container which is spun up as part of the tests, doing away with the somewhat problematic ioredis-mock which was breaking some tests due to the addition of the changes for multi-dev collab.
This commit is contained in:
parent
651d50a064
commit
249625ad1a
|
@ -97,7 +97,6 @@ const environment = {
|
||||||
REDIS_URL: process.env.REDIS_URL || "localhost:6379",
|
REDIS_URL: process.env.REDIS_URL || "localhost:6379",
|
||||||
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
||||||
REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
|
REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
|
||||||
MOCK_REDIS: process.env.MOCK_REDIS,
|
|
||||||
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
||||||
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
||||||
AWS_REGION: process.env.AWS_REGION,
|
AWS_REGION: process.env.AWS_REGION,
|
||||||
|
|
|
@ -21,6 +21,7 @@ export * as context from "./context"
|
||||||
export * as cache from "./cache"
|
export * as cache from "./cache"
|
||||||
export * as objectStore from "./objectStore"
|
export * as objectStore from "./objectStore"
|
||||||
export * as redis from "./redis"
|
export * as redis from "./redis"
|
||||||
|
export { Client as RedisClient } from "./redis"
|
||||||
export * as locks from "./redis/redlockImpl"
|
export * as locks from "./redis/redlockImpl"
|
||||||
export * as utils from "./utils"
|
export * as utils from "./utils"
|
||||||
export * as errors from "./errors"
|
export * as errors from "./errors"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
// ioredis mock is all in memory
|
// ioredis mock is all in memory
|
||||||
const Redis = env.MOCK_REDIS ? require("ioredis-mock") : require("ioredis")
|
import Redis from "ioredis"
|
||||||
import {
|
import {
|
||||||
addDbPrefix,
|
addDbPrefix,
|
||||||
removeDbPrefix,
|
removeDbPrefix,
|
||||||
|
@ -21,11 +21,6 @@ let CLIENTS: { [key: number]: any } = {}
|
||||||
|
|
||||||
let CONNECTED = false
|
let CONNECTED = false
|
||||||
|
|
||||||
// mock redis always connected
|
|
||||||
if (env.MOCK_REDIS) {
|
|
||||||
CONNECTED = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function pickClient(selectDb: number): any {
|
function pickClient(selectDb: number): any {
|
||||||
return CLIENTS[selectDb]
|
return CLIENTS[selectDb]
|
||||||
}
|
}
|
||||||
|
@ -62,10 +57,6 @@ function init(selectDb = DEFAULT_SELECT_DB) {
|
||||||
if (client && CONNECTED) {
|
if (client && CONNECTED) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// testing uses a single in memory client
|
|
||||||
if (env.MOCK_REDIS) {
|
|
||||||
CLIENTS[selectDb] = new Redis(getRedisOptions())
|
|
||||||
}
|
|
||||||
// start the timer - only allowed 5 seconds to connect
|
// start the timer - only allowed 5 seconds to connect
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
if (!CONNECTED) {
|
if (!CONNECTED) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ export function getRedisOptions() {
|
||||||
opts.port = port
|
opts.port = port
|
||||||
opts.password = password
|
opts.password = password
|
||||||
}
|
}
|
||||||
return { opts, host, port, redisProtocolUrl }
|
return { opts, host, port: parseInt(port), redisProtocolUrl }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addDbPrefix(db: string, key: string) {
|
export function addDbPrefix(db: string, key: string) {
|
||||||
|
|
|
@ -157,7 +157,6 @@
|
||||||
"copyfiles": "2.4.1",
|
"copyfiles": "2.4.1",
|
||||||
"docker-compose": "0.23.17",
|
"docker-compose": "0.23.17",
|
||||||
"eslint": "6.8.0",
|
"eslint": "6.8.0",
|
||||||
"ioredis-mock": "7.2.0",
|
|
||||||
"is-wsl": "2.2.0",
|
"is-wsl": "2.2.0",
|
||||||
"jest": "29.5.0",
|
"jest": "29.5.0",
|
||||||
"jest-openapi": "0.14.2",
|
"jest-openapi": "0.14.2",
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import { redis } from "@budibase/backend-core"
|
import { redis, RedisClient } from "@budibase/backend-core"
|
||||||
import { getGlobalIDFromUserMetadataID } from "../db/utils"
|
import { getGlobalIDFromUserMetadataID } from "../db/utils"
|
||||||
import { ContextUser } from "@budibase/types"
|
import { ContextUser } from "@budibase/types"
|
||||||
|
import env from "../environment"
|
||||||
|
|
||||||
const APP_DEV_LOCK_SECONDS = 600
|
const APP_DEV_LOCK_SECONDS = 600
|
||||||
const AUTOMATION_TEST_FLAG_SECONDS = 60
|
const AUTOMATION_TEST_FLAG_SECONDS = 60
|
||||||
let devAppClient: any, debounceClient: any, flagClient: any, socketClient: any
|
let devAppClient: RedisClient,
|
||||||
|
debounceClient: RedisClient,
|
||||||
|
flagClient: RedisClient,
|
||||||
|
socketClient: RedisClient
|
||||||
|
|
||||||
// We need to maintain a duplicate client for socket.io pub/sub
|
// We need to maintain a duplicate client for socket.io pub/sub
|
||||||
let socketSubClient: any
|
let socketSubClient: any
|
||||||
|
|
|
@ -49,12 +49,12 @@ export default class BuilderSocket extends Socket {
|
||||||
|
|
||||||
emitTableUpdate(ctx: any, table: Table) {
|
emitTableUpdate(ctx: any, table: Table) {
|
||||||
this.io.in(ctx.appId).emit("table-change", { id: table._id, table })
|
this.io.in(ctx.appId).emit("table-change", { id: table._id, table })
|
||||||
gridSocket.emitTableUpdate(table)
|
gridSocket?.emitTableUpdate(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
emitTableDeletion(ctx: any, id: string) {
|
emitTableDeletion(ctx: any, id: string) {
|
||||||
this.io.in(ctx.appId).emit("table-change", { id, table: null })
|
this.io.in(ctx.appId).emit("table-change", { id, table: null })
|
||||||
gridSocket.emitTableDeletion(id)
|
gridSocket?.emitTableDeletion(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
emitDatasourceUpdate(ctx: any, datasource: Datasource) {
|
emitDatasourceUpdate(ctx: any, datasource: Datasource) {
|
||||||
|
|
|
@ -3,15 +3,19 @@ import Koa from "koa"
|
||||||
import ClientAppSocket from "./client"
|
import ClientAppSocket from "./client"
|
||||||
import GridSocket from "./grid"
|
import GridSocket from "./grid"
|
||||||
import BuilderSocket from "./builder"
|
import BuilderSocket from "./builder"
|
||||||
|
import env from "../environment"
|
||||||
|
|
||||||
let clientAppSocket: ClientAppSocket
|
let clientAppSocket: ClientAppSocket | undefined
|
||||||
let gridSocket: GridSocket
|
let gridSocket: GridSocket | undefined
|
||||||
let builderSocket: BuilderSocket
|
let builderSocket: BuilderSocket | undefined
|
||||||
|
|
||||||
export const initialise = (app: Koa, server: http.Server) => {
|
export const initialise = (app: Koa, server: http.Server) => {
|
||||||
clientAppSocket = new ClientAppSocket(app, server)
|
// currently we use ioredis-mock which doesn't work with the websocket system for testing
|
||||||
gridSocket = new GridSocket(app, server)
|
if (!env.isTest()) {
|
||||||
builderSocket = new BuilderSocket(app, server)
|
clientAppSocket = new ClientAppSocket(app, server)
|
||||||
|
gridSocket = new GridSocket(app, server)
|
||||||
|
builderSocket = new BuilderSocket(app, server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { clientAppSocket, gridSocket, builderSocket }
|
export { clientAppSocket, gridSocket, builderSocket }
|
||||||
|
|
14
yarn.lock
14
yarn.lock
|
@ -11846,7 +11846,7 @@ fecha@^4.2.0:
|
||||||
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
|
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
|
||||||
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==
|
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==
|
||||||
|
|
||||||
fengari-interop@^0.1.2, fengari-interop@^0.1.3:
|
fengari-interop@^0.1.2:
|
||||||
version "0.1.3"
|
version "0.1.3"
|
||||||
resolved "https://registry.yarnpkg.com/fengari-interop/-/fengari-interop-0.1.3.tgz#3ad37a90e7430b69b365441e9fc0ba168942a146"
|
resolved "https://registry.yarnpkg.com/fengari-interop/-/fengari-interop-0.1.3.tgz#3ad37a90e7430b69b365441e9fc0ba168942a146"
|
||||||
integrity sha512-EtZ+oTu3kEwVJnoymFPBVLIbQcCoy9uWCVnMA6h3M/RqHkUBsLYp29+RRHf9rKr6GwjubWREU1O7RretFIXjHw==
|
integrity sha512-EtZ+oTu3kEwVJnoymFPBVLIbQcCoy9uWCVnMA6h3M/RqHkUBsLYp29+RRHf9rKr6GwjubWREU1O7RretFIXjHw==
|
||||||
|
@ -13893,16 +13893,6 @@ ioredis-mock@5.8.0:
|
||||||
lodash "^4.17.21"
|
lodash "^4.17.21"
|
||||||
standard-as-callback "^2.1.0"
|
standard-as-callback "^2.1.0"
|
||||||
|
|
||||||
ioredis-mock@7.2.0:
|
|
||||||
version "7.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/ioredis-mock/-/ioredis-mock-7.2.0.tgz#48f006c07ef7f1f93f75e60d8f9035fa46c4ef0a"
|
|
||||||
integrity sha512-xzABBG3NhfDBGxH1KX9n6vs7WGNn9lhcxMT3b+vjynVImxlUV+vOXU+tjGzSUnGmx4IYllA8RqbXN8z6ROMPVA==
|
|
||||||
dependencies:
|
|
||||||
fengari "^0.1.4"
|
|
||||||
fengari-interop "^0.1.3"
|
|
||||||
redis-commands "^1.7.0"
|
|
||||||
standard-as-callback "^2.1.0"
|
|
||||||
|
|
||||||
ioredis@4.28.0:
|
ioredis@4.28.0:
|
||||||
version "4.28.0"
|
version "4.28.0"
|
||||||
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.0.tgz#5a2be3f37ff2075e2332f280eaeb02ab4d9ff0d3"
|
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.0.tgz#5a2be3f37ff2075e2332f280eaeb02ab4d9ff0d3"
|
||||||
|
@ -21649,7 +21639,7 @@ redent@^3.0.0:
|
||||||
indent-string "^4.0.0"
|
indent-string "^4.0.0"
|
||||||
strip-indent "^3.0.0"
|
strip-indent "^3.0.0"
|
||||||
|
|
||||||
redis-commands@1.7.0, redis-commands@^1.7.0:
|
redis-commands@1.7.0:
|
||||||
version "1.7.0"
|
version "1.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89"
|
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89"
|
||||||
integrity sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==
|
integrity sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==
|
||||||
|
|
Loading…
Reference in New Issue