Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Aug 2, 2024
1 parent 395e971 commit cbfdb1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.testFramework.EditorTestUtil
import com.intellij.testFramework.HeavyPlatformTestCase
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.testFramework.runInEdtAndWait
Expand Down Expand Up @@ -50,7 +51,7 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {
LensesService.getInstance(project).removeListener(this)
CodyAgentService.getInstance(myFixture.project).apply {
try {
stopAgent(project)
stopAgent(project)?.get(ASYNC_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
} catch (x: Exception) {
logger.warn("Error shutting down agent", x)
}
Expand All @@ -77,8 +78,12 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {
val workspaceRootUri = ConfigUtil.getWorkspaceRootPath(project)

// We copy the test resources there manually, bypassing Gradle, which is picky.
// We also ensure that all files are properly refreshed to the VFS.
val testDataPath = Paths.get(workspaceRootUri.toString(), "src/").toFile()
testDataPath.deleteRecursively()
HeavyPlatformTestCase.synchronizeTempDirVfs(testDataPath.toPath())
testResourcesDir.copyRecursively(testDataPath, overwrite = true)
HeavyPlatformTestCase.synchronizeTempDirVfs(testDataPath.toPath())

// This useful setting lets us tell the fixture to look where we copied them.
myFixture.testDataPath = testDataPath.path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ class CodyAgentService(private val project: Project) : Disposable {
return codyAgent
}

fun stopAgent(project: Project?) {
fun stopAgent(project: Project?): CompletableFuture<Unit>? {
try {
codyAgent.getNow(null)?.shutdown()
return codyAgent.getNow(null)?.shutdown()
} catch (e: Exception) {
logger.warn("Failed to stop Cody agent gracefully", e)
return CompletableFuture.failedFuture(e)
} finally {
codyAgent = CompletableFuture()
project?.let { CodyStatusService.resetApplication(it) }
Expand Down

0 comments on commit cbfdb1a

Please sign in to comment.