Skip to content

Commit

Permalink
test: disable test-specific caching in TestGarden
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Oct 5, 2023
1 parent ee7645c commit 2a6b505
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions core/src/util/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import { WorkflowConfig } from "../config/workflow"
import { LogEntry } from "../logger/log-entry"
import { RuntimeContext } from "../runtime-context"
import { GardenModule } from "../types/module"
import { findByName, getNames, ValueOf, isPromise, serializeObject, hashString, uuidv4 } from "./util"
import { findByName, getNames, ValueOf, isPromise, uuidv4 } from "./util"
import { GardenBaseError, GardenError } from "../exceptions"
import { EventBus, Events } from "../events"
import { dedent } from "./string"
import pathIsInside from "path-is-inside"
import { resolve } from "path"
import { DEFAULT_API_VERSION, GARDEN_CORE_ROOT } from "../constants"
import { getLogger } from "../logger/logger"
import { ConfigGraph } from "../config-graph"
import stripAnsi from "strip-ansi"
import { VcsHandler } from "../vcs/vcs"

Expand Down Expand Up @@ -120,7 +119,7 @@ const defaultCommandinfo = { name: "test", args: {}, opts: {} }
const repoRoot = resolve(GARDEN_CORE_ROOT, "..")

const paramCache: { [key: string]: GardenParams } = {}
const configGraphCache: { [key: string]: ConfigGraph } = {}
// const configGraphCache: { [key: string]: ConfigGraph } = {}

export type TestGardenOpts = Partial<GardenOpts> & { noCache?: boolean; noTempDir?: boolean }

Expand All @@ -143,9 +142,11 @@ export class TestGarden extends Garden {
opts?: TestGardenOpts
): Promise<InstanceType<T>> {
// Cache the resolved params to save a bunch of time during tests
const cacheKey = opts?.noCache
? undefined
: hashString(serializeObject([currentDirectory, { ...opts, log: undefined }]))
// TODO: enable caching and fix failing tests
const cacheKey = undefined
// const cacheKey = opts?.noCache
// ? undefined
// : hashString(serializeObject([currentDirectory, { ...opts, log: undefined }]))

let params: GardenParams

Expand Down Expand Up @@ -179,31 +180,32 @@ export class TestGarden extends Garden {
*/
async getConfigGraph(params: { log: LogEntry; runtimeContext?: RuntimeContext; emit: boolean; noCache?: boolean }) {
// We don't try to cache if a runtime context is given (TODO: might revisit that)
let cacheKey: string | undefined = undefined

if (this.cacheKey && !params.noCache) {
const moduleConfigHash = hashString(serializeObject(await this.getRawModuleConfigs()))
const runtimeContextHash = hashString(serializeObject(params.runtimeContext || {}))
cacheKey = [this.cacheKey, moduleConfigHash, runtimeContextHash].join("-")
}

if (cacheKey) {
const cached = configGraphCache[cacheKey]
if (cached) {
// Clone the cached graph and return
const clone = new ConfigGraph([], {})
for (const key of Object.getOwnPropertyNames(cached)) {
clone[key] = cloneDeep(cached[key])
}
return clone
}
}
// TODO: enable caching and fix failing tests
// let cacheKey: string | undefined = undefined
//
// if (this.cacheKey && !params.noCache) {
// const moduleConfigHash = hashString(serializeObject(await this.getRawModuleConfigs()))
// const runtimeContextHash = hashString(serializeObject(params.runtimeContext || {}))
// cacheKey = [this.cacheKey, moduleConfigHash, runtimeContextHash].join("-")
// }
//
// if (cacheKey) {
// const cached = configGraphCache[cacheKey]
// if (cached) {
// // Clone the cached graph and return
// const clone = new ConfigGraph([], {})
// for (const key of Object.getOwnPropertyNames(cached)) {
// clone[key] = cloneDeep(cached[key])
// }
// return clone
// }
// }

const graph = await super.getConfigGraph(params)

if (cacheKey) {
configGraphCache[cacheKey] = graph
}
// if (cacheKey) {
// configGraphCache[cacheKey] = graph
// }
return graph
}

Expand Down

0 comments on commit 2a6b505

Please sign in to comment.