Fix for cypress test issues, when metadata is updated rapidly it could get into a bad state - this should resolve it.
This commit is contained in:
parent
aaff5260d3
commit
7170c00a4f
|
@ -67,7 +67,19 @@ exports.getAppMetadata = async (appId, CouchDB = null) => {
|
||||||
return metadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.invalidateAppMetadata = async appId => {
|
/**
|
||||||
|
* Invalidate/reset the cached metadata when a change occurs in the db.
|
||||||
|
* @param appId {string} the cache key to bust/update.
|
||||||
|
* @param newMetadata {object|undefined} optional - can simply provide the new metadata to update with.
|
||||||
|
* @return {Promise<void>} will respond with success when cache is updated.
|
||||||
|
*/
|
||||||
|
exports.invalidateAppMetadata = async (appId, newMetadata = null) => {
|
||||||
|
if (!appId) {
|
||||||
|
throw "Cannot invalidate if no app ID provided."
|
||||||
|
}
|
||||||
const client = await redis.getAppClient()
|
const client = await redis.getAppClient()
|
||||||
await client.delete(appId)
|
await client.delete(appId)
|
||||||
|
if (newMetadata) {
|
||||||
|
await client.store(appId, newMetadata, EXPIRY_SECONDS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,10 @@ module.exports = (
|
||||||
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
|
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
|
||||||
return next()
|
return next()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// invalid token, clear the cookie
|
||||||
|
if (err && err.name === "JsonWebTokenError") {
|
||||||
|
clearCookie(ctx, Cookies.Auth)
|
||||||
|
}
|
||||||
// allow configuring for public access
|
// allow configuring for public access
|
||||||
if ((opts && opts.publicAllowed) || publicEndpoint) {
|
if ((opts && opts.publicAllowed) || publicEndpoint) {
|
||||||
finalise(ctx, { authenticated: false, version, publicEndpoint })
|
finalise(ctx, { authenticated: false, version, publicEndpoint })
|
||||||
|
|
|
@ -5,19 +5,19 @@
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const tmpdir = path.join(require("os").tmpdir(), ".budibase")
|
const tmpdir = path.join(require("os").tmpdir(), ".budibase")
|
||||||
|
|
||||||
const MAIN_PORT = "4002"
|
const MAIN_PORT = "10001"
|
||||||
const WORKER_PORT = "4001"
|
const WORKER_PORT = "10002"
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
process.env.PORT = "4001"
|
process.env.PORT = MAIN_PORT
|
||||||
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
|
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
|
||||||
process.env.NODE_ENV = "cypress"
|
process.env.NODE_ENV = "cypress"
|
||||||
process.env.ENABLE_ANALYTICS = "false"
|
process.env.ENABLE_ANALYTICS = "false"
|
||||||
process.env.JWT_SECRET = "budibase"
|
process.env.JWT_SECRET = "budibase"
|
||||||
process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
|
process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
|
||||||
process.env.SELF_HOSTED = "1"
|
process.env.SELF_HOSTED = "1"
|
||||||
process.env.WORKER_URL = "http://localhost:4002/"
|
process.env.WORKER_URL = `http://localhost:${WORKER_PORT}/`
|
||||||
process.env.MINIO_URL = `http://localhost:4001/`
|
process.env.MINIO_URL = `http://localhost:${MAIN_PORT}/`
|
||||||
process.env.MINIO_ACCESS_KEY = "budibase"
|
process.env.MINIO_ACCESS_KEY = "budibase"
|
||||||
process.env.MINIO_SECRET_KEY = "budibase"
|
process.env.MINIO_SECRET_KEY = "budibase"
|
||||||
process.env.COUCH_DB_USER = "budibase"
|
process.env.COUCH_DB_USER = "budibase"
|
||||||
|
@ -28,6 +28,6 @@ process.env.ALLOW_DEV_AUTOMATIONS = "1"
|
||||||
// don't make this a variable or top level require
|
// don't make this a variable or top level require
|
||||||
// it will cause environment module to be loaded prematurely
|
// it will cause environment module to be loaded prematurely
|
||||||
const server = require("../src/app")
|
const server = require("../src/app")
|
||||||
process.env.PORT = "4002"
|
process.env.PORT = WORKER_PORT
|
||||||
const worker = require("../../worker/src/index")
|
const worker = require("../../worker/src/index")
|
||||||
process.env.PORT = "4001"
|
process.env.PORT = MAIN_PORT
|
|
@ -255,6 +255,7 @@ exports.create = async ctx => {
|
||||||
await createApp(appId)
|
await createApp(appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await appCache.invalidateAppMetadata(appId, newApplication)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = newApplication
|
ctx.body = newApplication
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ async function redirect(ctx, method, path = "global") {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
ctx.throw(response.status, response.statusText)
|
const err = await response.text()
|
||||||
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
const cookie = response.headers.get("set-cookie")
|
const cookie = response.headers.get("set-cookie")
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
|
|
|
@ -51,8 +51,9 @@ async function updateAppUpdatedAt(ctx) {
|
||||||
const db = new CouchDB(appId)
|
const db = new CouchDB(appId)
|
||||||
const metadata = await db.get(DocumentTypes.APP_METADATA)
|
const metadata = await db.get(DocumentTypes.APP_METADATA)
|
||||||
metadata.updatedAt = new Date().toISOString()
|
metadata.updatedAt = new Date().toISOString()
|
||||||
await db.put(metadata)
|
const response = await db.put(metadata)
|
||||||
await appCache.invalidateAppMetadata(appId)
|
metadata._rev = response.rev
|
||||||
|
await appCache.invalidateAppMetadata(appId, metadata)
|
||||||
// set a new debounce record with a short TTL
|
// set a new debounce record with a short TTL
|
||||||
await setDebounce(appId, DEBOUNCE_TIME_SEC)
|
await setDebounce(appId, DEBOUNCE_TIME_SEC)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue