Add FlakySpec Test Suite (#768)

This commit is contained in:
Dmitry Bushev 2020-05-20 19:05:09 +03:00 committed by GitHub
parent 9a59c80e8b
commit 5be8ec20bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 19 deletions

View File

@ -4,6 +4,7 @@ import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import org.enso.jsonrpc.Id.Number
import org.enso.jsonrpc.{Request, ResponseResult, Unused}
import org.enso.jsonrpc.test.FlakySpec
import org.enso.languageserver.monitoring.MonitoringApi
import org.enso.languageserver.monitoring.MonitoringProtocol.{Ping, Pong}
import org.scalatest.flatspec.AnyFlatSpecLike
@ -15,7 +16,8 @@ class PingHandlerSpec
extends TestKit(ActorSystem("TestSystem"))
with ImplicitSender
with AnyFlatSpecLike
with Matchers {
with Matchers
with FlakySpec {
"A PingHandler" must "scatter pings to all subsystems" in {
//given
@ -59,7 +61,7 @@ class PingHandlerSpec
system.stop(actorUnderTest)
}
it must "stop without replying when some of subsystems don't reply on time" in {
it must "stop without replying when some of subsystems don't reply on time" taggedAs(Flaky) in {
//given
val subsystem1 = TestProbe()
val subsystem2 = TestProbe()

View File

@ -6,6 +6,7 @@ import java.util.UUID
import com.google.flatbuffers.FlatBufferBuilder
import org.apache.commons.io.FileUtils
import org.enso.jsonrpc.test.FlakySpec
import org.enso.languageserver.protocol.binary.{
InboundPayload,
OutboundMessage,
@ -21,13 +22,13 @@ import org.enso.languageserver.websocket.binary.factory.{
import scala.io.Source
class BinaryFileManipulationTest extends BaseBinaryServerTest {
class BinaryFileManipulationTest extends BaseBinaryServerTest with FlakySpec {
implicit private val decoder = OutboundMessageDecoder
"A WriteFileCommand" must {
"persist binary contents of a file" in {
"persist binary contents of a file" taggedAs(Flaky) in {
//given
val requestId = UUID.randomUUID()
val filename = "foo.bin"

View File

@ -3,6 +3,7 @@ package org.enso.languageserver.websocket.binary
import java.util.UUID
import com.google.flatbuffers.FlatBufferBuilder
import org.enso.jsonrpc.test.FlakySpec
import org.enso.languageserver.protocol.binary.{
InboundPayload,
OutboundMessage,
@ -13,13 +14,13 @@ import org.enso.languageserver.websocket.binary.factory.{
SessionInitFactory
}
class BinarySessionManagementTest extends BaseBinaryServerTest {
class BinarySessionManagementTest extends BaseBinaryServerTest with FlakySpec {
implicit private val decoder = OutboundMessageDecoder
"Session Init cmd" must {
"return empty SessionInitResponse" in {
"return empty SessionInitResponse" taggedAs(Flaky) in {
//given
val client = newWsClient()
val clientId = UUID.randomUUID()

View File

@ -3,6 +3,7 @@ package org.enso.languageserver.websocket.binary
import java.nio.ByteBuffer
import java.util.UUID
import org.enso.jsonrpc.test.FlakySpec
import org.enso.languageserver.protocol.binary.{
OutboundMessage,
OutboundPayload,
@ -14,13 +15,16 @@ import org.enso.languageserver.runtime.ContextRegistryProtocol.{
}
import org.scalatest.concurrent.Eventually
class VisualisationProtocolTest extends BaseBinaryServerTest with Eventually {
class VisualisationProtocolTest
extends BaseBinaryServerTest
with Eventually
with FlakySpec {
implicit private val decoder = OutboundMessageDecoder
"A visualisation binary protocol" must {
"push visualisation updates when controller receives notification" in {
"push visualisation updates when controller receives notification" taggedAs(Flaky) in {
//given
val client = newWsClient()
val data = Array[Byte](1, 2, 3)

View File

@ -0,0 +1,22 @@
package org.enso.jsonrpc.test
import org.scalatest._
/**
* Trait is used to mark the tests in the suite as _flaky_ and make them
* pass. It changes the behavior for failed tests to return 'pending' instead
* of failing the suite.
*/
trait FlakySpec extends TestSuite {
/** Tags test as _flaky_. */
object Flaky extends Tag("flaky")
override def withFixture(test: NoArgTest): Outcome =
super.withFixture(test) match {
case Failed(_) | Canceled(_) if test.tags.contains(Flaky.name) =>
Pending
case outcome =>
outcome
}
}

View File

@ -5,6 +5,7 @@ import java.util.UUID
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.miguno.akka.testing.VirtualTime
import org.enso.jsonrpc.test.FlakySpec
import org.enso.languageserver.boot.LifecycleComponent.ComponentRestarted
import org.enso.languageserver.boot.{LanguageServerConfig, LifecycleComponent}
import org.enso.projectmanager.boot.configuration.SupervisionConfig
@ -32,9 +33,10 @@ class LanguageServerSupervisorSpec
with AnyFlatSpecLike
with Matchers
with BeforeAndAfterAll
with MockitoSugar {
with MockitoSugar
with FlakySpec {
"A language supervisor" should "monitor language server by sending ping requests on regular basis" in new TestCtx {
"A language supervisor" should "monitor language server by sending ping requests on regular basis" taggedAs (Flaky) in new TestCtx {
//given
val probe = TestProbe()
fakeServer.withBehaviour {

View File

@ -6,14 +6,14 @@ import java.util.UUID
import io.circe.literal._
import io.circe.parser.parse
import org.enso.jsonrpc.test.FlakySpec
import org.enso.projectmanager.data.Socket
class ProjectManagementApiSpec extends BaseServerSpec {
class ProjectManagementApiSpec extends BaseServerSpec with FlakySpec {
"project/create" must {
pending // #652
"check if project name is not empty" in {
"check if project name is not empty" taggedAs(Flaky) in {
val client = new WsTestClient(address)
client.send(json"""
{ "jsonrpc": "2.0",
@ -126,7 +126,6 @@ class ProjectManagementApiSpec extends BaseServerSpec {
}
"project/delete" must {
pending // #652
"fail when project doesn't exist" in {
val client = new WsTestClient(address)
@ -152,7 +151,7 @@ class ProjectManagementApiSpec extends BaseServerSpec {
}
"fail when project is running" in {
"fail when project is running" taggedAs (Flaky) in {
//given
implicit val client = new WsTestClient(address)
val projectId = createProject("foo")
@ -216,7 +215,6 @@ class ProjectManagementApiSpec extends BaseServerSpec {
}
"project/open" must {
pending // #652
"fail when project doesn't exist" in {
val client = new WsTestClient(address)
@ -311,7 +309,6 @@ class ProjectManagementApiSpec extends BaseServerSpec {
}
"project/close" must {
pending // #652
"fail when project is not open" in {
val client = new WsTestClient(address)
@ -368,7 +365,6 @@ class ProjectManagementApiSpec extends BaseServerSpec {
}
"project/listRecent" must {
pending // #652
"return a list sorted by creation time if none of projects was opened" in {
implicit val client = new WsTestClient(address)
@ -492,7 +488,7 @@ class ProjectManagementApiSpec extends BaseServerSpec {
val Right(openReply) = parse(client.expectMessage())
val socketField = openReply.hcursor
.downField("result")
.downField("languageServerRpcAddress")
.downField("languageServerJsonAddress")
val Right(host) = socketField.downField("host").as[String]
val Right(port) = socketField.downField("port").as[Int]
Socket(host, port)