Carry position for project management operations (#8589)

It's quite annoying to debug problems when position is inaccurate.
Example: https://github.com/enso-org/enso/actions/runs/7260847544/job/19780840613?pr=8577#step:10:2238
This commit is contained in:
Hubert Plociniczak 2023-12-19 16:37:15 +01:00 committed by GitHub
parent f0c2a5fa7f
commit fce6d5dce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 25 deletions

View File

@ -10,6 +10,7 @@ import io.circe.parser.parse
import nl.gn0s1s.bump.SemVer
import org.enso.projectmanager.data.{MissingComponentAction, Socket}
import org.enso.projectmanager.protocol.ProjectManagementApi.ProjectOpen
import org.scalactic.source.Position
import scala.concurrent.duration._
@ -20,7 +21,7 @@ trait ProjectManagementOps { this: BaseServerSpec =>
nameSuffix: Option[Int] = None,
projectTemplate: Option[String] = None,
missingComponentAction: Option[MissingComponentAction] = None
)(implicit client: WsTestClient): UUID = {
)(implicit client: WsTestClient, pos: Position): UUID = {
val fields = Seq("name" -> name.asJson) ++
missingComponentAction
.map(a => "missingComponentAction" -> a.asJson)
@ -55,7 +56,7 @@ trait ProjectManagementOps { this: BaseServerSpec =>
def openProject(
projectId: UUID
)(implicit client: WsTestClient): Socket = {
)(implicit client: WsTestClient, pos: Position): Socket = {
client.send(json"""
{ "jsonrpc": "2.0",
"method": "project/open",
@ -76,7 +77,10 @@ trait ProjectManagementOps { this: BaseServerSpec =>
socket.fold(fail(s"Failed to decode json: $openReply", _), identity)
}
def openProjectData(implicit client: WsTestClient): ProjectOpen.Result = {
def openProjectData(implicit
client: WsTestClient,
pos: Position
): ProjectOpen.Result = {
val Right(openReply) = parse(client.expectMessage(20.seconds.dilated))
val openResult = for {
result <- openReply.hcursor.downExpectedField("result")
@ -104,12 +108,12 @@ trait ProjectManagementOps { this: BaseServerSpec =>
namespace
)
}
openResult.getOrElse(throw new Exception("Should have worked."))
openResult.getOrElse(fail("Should have worked."))
}
def closeProject(
projectId: UUID
)(implicit client: WsTestClient): Unit = {
)(implicit client: WsTestClient, pos: Position): Unit = {
client.send(json"""
{ "jsonrpc": "2.0",
"method": "project/close",
@ -133,7 +137,7 @@ trait ProjectManagementOps { this: BaseServerSpec =>
def deleteProject(
projectId: UUID
)(implicit client: WsTestClient): Unit = {
)(implicit client: WsTestClient, pos: Position): Unit = {
client.send(json"""
{ "jsonrpc": "2.0",
"method": "project/delete",

View File

@ -9,6 +9,7 @@ import org.enso.projectmanager.{BaseServerSpec, ProjectManagementOps}
import org.enso.runtimeversionmanager.CurrentVersion
import org.enso.runtimeversionmanager.test.OverrideTestVersionSuite
import org.enso.testkit.FlakySpec
import org.scalactic.source.Position
import java.io.File
import java.nio.file.{Files, Paths}
@ -548,11 +549,11 @@ class ProjectManagementApiSpec
"not start new Language Server if one is running" taggedAs Flaky in {
val client1 = new WsTestClient(address)
val projectId = createProject("Foo")(client1)
val projectId = createProject("Foo")(client1, implicitly[Position])
//when
val socket1 = openProject(projectId)(client1)
val socket1 = openProject(projectId)(client1, implicitly[Position])
val client2 = new WsTestClient(address)
val socket2 = openProject(projectId)(client2)
val socket2 = openProject(projectId)(client2, implicitly[Position])
//then
socket2 shouldBe socket1
//teardown
@ -575,8 +576,8 @@ class ProjectManagementApiSpec
}
}
""")
closeProject(projectId)(client2)
deleteProject(projectId)(client1)
closeProject(projectId)(client2, implicitly[Position])
deleteProject(projectId)(client1, implicitly[Position])
}
"start the Language Server after moving the directory" taggedAs Flaky in {

View File

@ -12,6 +12,7 @@ import java.util.UUID
import org.enso.projectmanager.{BaseServerSpec, ProjectManagementOps}
import org.enso.runtimeversionmanager.test.OverrideTestVersionSuite
import org.enso.testkit.FlakySpec
import org.scalactic.source.Position
import scala.concurrent.duration._
@ -58,16 +59,16 @@ class ProjectShutdownSpec
"ensure language server shuts down immediately when requesting to close the project" in {
val client1 = new WsTestClient(address)
val projectId = createProject("Foo")(client1)
openProject(projectId)(client1)
closeProject(projectId)(client1)
deleteProject(projectId)(client1)
val projectId = createProject("Foo")(client1, implicitly[Position])
openProject(projectId)(client1, implicitly[Position])
closeProject(projectId)(client1, implicitly[Position])
deleteProject(projectId)(client1, implicitly[Position])
}
"ensure language server does not shutdown immediately after last client disconnects" in {
val client1 = new WsTestClient(address)
val projectId = createProject("Foo")(client1)
val socket1 = openProject(projectId)(client1)
val projectId = createProject("Foo")(client1, implicitly[Position])
val socket1 = openProject(projectId)(client1, implicitly[Position])
system.eventStream.publish(
ClientDisconnected(clientUUID, socket1.port)
)
@ -92,7 +93,7 @@ class ProjectShutdownSpec
}
""")
val client2 = new WsTestClient(address)
val socket2 = openProject(projectId)(client2)
val socket2 = openProject(projectId)(client2, implicitly[Position])
socket2 shouldBe socket1
client2.send(s"""
@ -116,14 +117,14 @@ class ProjectShutdownSpec
}
""")
closeProject(projectId)(client2)
deleteProject(projectId)(client2)
closeProject(projectId)(client2, implicitly[Position])
deleteProject(projectId)(client2, implicitly[Position])
}
"ensure language server does eventually shutdown after last client disconnects" in {
val client = new WsTestClient(address)
val projectId = createProject("Foo")(client)
val socket1 = openProject(projectId)(client)
val projectId = createProject("Foo")(client, implicitly[Position])
val socket1 = openProject(projectId)(client, implicitly[Position])
system.eventStream.publish(
ClientDisconnected(clientUUID, socket1.port)
)
@ -151,11 +152,11 @@ class ProjectShutdownSpec
(timeoutConfig.delayedShutdownTimeout + timeoutConfig.shutdownTimeout + 1.second).toMillis
)
val client2 = new WsTestClient(address)
val socket2 = openProject(projectId)(client2)
val socket2 = openProject(projectId)(client2, implicitly[Position])
socket2 shouldNot be(socket1)
closeProject(projectId)(client2)
deleteProject(projectId)(client2)
closeProject(projectId)(client2, implicitly[Position])
deleteProject(projectId)(client2, implicitly[Position])
}
}