From 131e72b16207d3abbfc193d86335a90cefbf0f80 Mon Sep 17 00:00:00 2001 From: Dave Bartolomeo Date: Fri, 14 Oct 2022 15:32:03 -0400 Subject: [PATCH] Decouple `join-order.ts` from VS Code for testing purposes --- extensions/ql-vscode/src/extension.ts | 3 ++- extensions/ql-vscode/src/log-insights/join-order.ts | 6 ++++-- extensions/ql-vscode/test/pure-tests/log-scanner.test.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index be8713cd4..1c1beef52 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -33,6 +33,7 @@ import { CliConfigListener, DistributionConfigListener, isCanary, + joinOrderWarningThreshold, MAX_QUERIES, QueryHistoryConfigListener, QueryServerConfigListener @@ -518,7 +519,7 @@ async function activateWithInstalledDistribution( void logger.log('Initializing evaluation log scanners.'); const logScannerService = new LogScannerService(qhm); ctx.subscriptions.push(logScannerService); - ctx.subscriptions.push(logScannerService.scanners.registerLogScannerProvider(new JoinOrderScannerProvider())); + ctx.subscriptions.push(logScannerService.scanners.registerLogScannerProvider(new JoinOrderScannerProvider(() => joinOrderWarningThreshold()))); void logger.log('Reading query history'); await qhm.readQueryHistory(); diff --git a/extensions/ql-vscode/src/log-insights/join-order.ts b/extensions/ql-vscode/src/log-insights/join-order.ts index 2dd33e378..7dbff9625 100644 --- a/extensions/ql-vscode/src/log-insights/join-order.ts +++ b/extensions/ql-vscode/src/log-insights/join-order.ts @@ -1,5 +1,4 @@ import * as I from 'immutable'; -import { joinOrderWarningThreshold } from '../config'; import { EvaluationLogProblemReporter, EvaluationLogScanner, EvaluationLogScannerProvider } from './log-scanner'; import { InLayer, ComputeRecursive, SummaryEvent, PipelineRun, ComputeSimple } from './log-summary'; @@ -453,8 +452,11 @@ class JoinOrderScanner implements EvaluationLogScanner { } export class JoinOrderScannerProvider implements EvaluationLogScannerProvider { + constructor(private readonly getThreshdold: () => number) { + } + public createScanner(problemReporter: EvaluationLogProblemReporter): EvaluationLogScanner { - const threshold = joinOrderWarningThreshold(); + const threshold = this.getThreshdold(); return new JoinOrderScanner(problemReporter, threshold); } } diff --git a/extensions/ql-vscode/test/pure-tests/log-scanner.test.ts b/extensions/ql-vscode/test/pure-tests/log-scanner.test.ts index db0e79f0f..6cf740930 100644 --- a/extensions/ql-vscode/test/pure-tests/log-scanner.test.ts +++ b/extensions/ql-vscode/test/pure-tests/log-scanner.test.ts @@ -31,7 +31,7 @@ class TestProblemReporter implements EvaluationLogProblemReporter { describe('log scanners', function() { it('should detect bad join orders', async function() { const scanners = new EvaluationLogScannerSet(); - scanners.registerLogScannerProvider(new JoinOrderScannerProvider()); + scanners.registerLogScannerProvider(new JoinOrderScannerProvider(() => 50)); const summaryPath = path.join(__dirname, 'evaluator-log-summaries/bad-join-order.jsonl'); const problemReporter = new TestProblemReporter(); await scanners.scanLog(summaryPath, problemReporter);