When rehydrating, always trigger a monitoring command unless the variant analysis is fully complete#1672
Conversation
| public async isVariantAnalysisComplete(variantAnalysis: VariantAnalysis): Promise<boolean> { | ||
| // It's only acceptable to have no scanned repos if the variant analysis is not in a final state. | ||
| // Otherwise it means the analysis hit some kind of internal error or there were no repos to scan. | ||
| if (variantAnalysis.scannedRepos === undefined || variantAnalysis.scannedRepos.length === 0) { | ||
| return variantAnalysis.status !== VariantAnalysisStatus.InProgress; | ||
| } | ||
|
|
||
| return (await Promise.all(variantAnalysis.scannedRepos.map(repo => this.isVariantAnalysisRepoComplete(variantAnalysis.id, repo)))).every(x => x); | ||
| } | ||
|
|
||
| private async isVariantAnalysisRepoComplete(variantAnalysisId: number, repo: VariantAnalysisScannedRepository): Promise<boolean> { | ||
| if (!hasRepoScanCompleted(repo)) { | ||
| return false; | ||
| } else if (!repoScanHasResults(repo)) { | ||
| return true; | ||
| } else { | ||
| const storageLocation = this.getVariantAnalysisStorageLocation(variantAnalysisId); | ||
| return await this.variantAnalysisResultsManager.isVariantAnalysisRepoDownloaded(storageLocation, repo.repository.fullName); | ||
| } | ||
| } |
There was a problem hiding this comment.
Since this doesn't depend on any instance variables, I think you can extract this to a function which is outside of the class. We could have a simple function like isVariantAnalysisComplete(variantAnalysisResultsManager: VariantAnalysisResultsManager, variantAnalysisStorageLocation: string, variantAnalysis: VariantAnalysis) which can be called from anywhere. This would also solve the problem of this being unnecessarily public since we can just export it and not think about its visibility.
There was a problem hiding this comment.
Agree with @koesie10 - this function can be extracted and unit tested/mocked independently.
If we want to avoid passing in the VariantAnalysisResultsManager, we could instead pass in a function that helps decide whether a repo has downloads.
There was a problem hiding this comment.
Thanks for the advice. That makes sense to me, to extract the method and pass in a function that checks whether the repo has downloads or not. This way we can keep the logic pure and contained to variant-analysis.ts (unless you have suggestions for somewhere better to put it). And we can test the logic of this method and the logic of rehydrating separately.
| * should be deleted. | ||
| */ | ||
| private async prepareStorageDirectory(variantAnalysisId: number): Promise<void> { | ||
| public async prepareStorageDirectory(variantAnalysisId: number): Promise<void> { |
There was a problem hiding this comment.
I don't really think this should be public since it's quite specific to the manager. I'm not sure how we can improve this though, but since this is public to be used in tests I think we can just copy the code to the tests.
There was a problem hiding this comment.
If you think it's better to keep this method private but duplicate the implementation in the tests, I'm happy to go with that approach.
|
Had to do a slightly complex merge resolution. The main conflicts were in I also ended up doing fef3159 because once I'd merge I was getting |
01e3fca to
c36fa0f
Compare
As discussed on slack, I'll not include this change in this PR. We'll address it separately. |
koesie10
left a comment
There was a problem hiding this comment.
LGTM, thanks for making these changes!
I believe the failing tests are due to missing an await on the isVariantAnalysisComplete calls in extensions/ql-vscode/test/pure-tests/variant-analysis.test.ts.
The method no longer accepts a second argument
|
Ok. I've now run all three test suites locally and they all pass. That had better be it 😦 |
|
Yay I think this is good to go, though I will wait until tomorrow because it may make sense to merge #1687 first otherwise we risk being unable to load the extension cleanly for all MRVA developers. |
The point of this PR is to trigger a monitoring command more often when we rehydrate a variant analysis. This should help with handling cases like when the analysis is complete but not all results are downloaded.
My end goal here is that it's always safe to just fire off a monitoring command and it'll do the right thing and get the variant analysis moving. This PR doesn't cover making the monitoring command handle all possible states perfectly, but I think in the currently implementation it won't be anything bad, so I think it's ok to consider this PR on its own and I'll look at opening a separate PR to make the monitoring command do the right thing in all cases.
This is the largest piece of code I've written in the extension on my own to date, and the tests are a bit complicated and I'm not sure I've done them correctly. Please don't hold back and do help me to do things properly.
Questions / concerns I have right now are:
isVariantAnalysisRepoDownloadedpublic. This seems fine to me but please let me know if not. Because I made it public I added some simple tests of it. Was this the right thing to do?isVariantAnalysisCompleteis public but it seemed the best solution for testing, so for the tests of rehydrating we can stubisVariantAnalysisCompleteand then have separate simpler tests of just that method. Otherwise there are a lot of different cases to cover and it didn't seem sensible doing the whole rehydrating in all of them.isVariantAnalysisCompleteshould not be inVariantAnalysisManager, but I'm not sure where to put it otherwise and also not sure it can be pulled out because it depends on the results manager.describes very heavily and tried to test only one thing at a time. Is this good style or not helpful?Checklist
ready-for-doc-reviewlabel there.