Skip to content

Commit 84206bc

Browse files
committed
SPARKC-635 fix flaky test in MultiplexingSchemaListenerTest
Without this change we had no guarantee that the assertion happens after any of the listener/event code. Let's try couple of times to assert on the sum to give listener/event code a chance to execute.
1 parent 1e89b98 commit 84206bc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

driver/src/test/scala/com/datastax/spark/connector/cql/MultiplexingSchemaListenerTest.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ package com.datastax.spark.connector.cql
77

88
import com.datastax.oss.driver.api.core.`type`.UserDefinedType
99
import com.datastax.oss.driver.api.core.metadata.schema.{AggregateMetadata, FunctionMetadata, KeyspaceMetadata, SchemaChangeListener, TableMetadata, ViewMetadata}
10+
import org.scalatest.concurrent.Eventually
1011
import org.scalatest.{BeforeAndAfterEach, FlatSpec, Matchers}
1112
import org.scalatestplus.mockito.MockitoSugar
1213

1314
import scala.collection.mutable
1415
import scala.concurrent.Future
1516
import scala.util.Random
1617

17-
class MultiplexingSchemaListenerTest extends FlatSpec with Matchers with MockitoSugar with BeforeAndAfterEach {
18+
class MultiplexingSchemaListenerTest extends FlatSpec with Matchers with MockitoSugar with BeforeAndAfterEach with Eventually {
1819
val r = new Random()
1920

2021
import scala.concurrent.ExecutionContext.Implicits.global
@@ -194,7 +195,6 @@ class MultiplexingSchemaListenerTest extends FlatSpec with Matchers with Mockito
194195
}
195196

196197
it should "allow listeners to be added while triggering events" in {
197-
var listeners = 0
198198
for (it <- 1 to 200) {
199199
Future (listener.addListener(new IncrementingSchemaListener()))
200200
Future (triggerAllEvents(5))
@@ -203,7 +203,9 @@ class MultiplexingSchemaListenerTest extends FlatSpec with Matchers with Mockito
203203
if (it % 10 == 0)
204204
Future (listener.clearListeners())
205205
}
206-
actionsDone.values.sum should be > 0
206+
eventually {
207+
actionsDone.values.sum should be > 0
208+
}
207209
}
208210

209211
}

0 commit comments

Comments
 (0)