Skip to content

Commit 2769d89

Browse files
Use retry to replace sleep
1 parent cdf10a0 commit 2769d89

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/src/test/scala/org/apache/openwhisk/core/scheduler/queue/test/ContainerCounterTests.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys
4242
import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys.inProgressContainer
4343
import org.apache.openwhisk.core.scheduler.queue.NamespaceContainerCount
4444
import org.apache.openwhisk.core.service.{DeleteEvent, PutEvent, UnwatchEndpoint, WatchEndpoint, WatcherService}
45+
import org.apache.openwhisk.utils.retry
4546
import org.junit.runner.RunWith
4647
import org.scalamock.scalatest.MockFactory
4748
import org.scalatest.concurrent.ScalaFutures
4849
import org.scalatest.{FlatSpecLike, Matchers}
4950
import org.scalatest.junit.JUnitRunner
5051

5152
import scala.concurrent.Future
52-
import scala.concurrent.duration.TimeUnit
53+
import scala.concurrent.duration._
5354

5455
@RunWith(classOf[JUnitRunner])
5556
class ContainerCounterTests
@@ -252,10 +253,10 @@ class ContainerCounterTests
252253
val watcher = system.actorOf(WatcherService.props(mockEtcdClient))
253254

254255
val ns = NamespaceContainerCount(namespace, mockEtcdClient, watcher)
255-
Thread.sleep(1000)
256-
257-
ns.inProgressContainerNumByNamespace shouldBe 0
258-
ns.existingContainerNumByNamespace shouldBe 0
256+
retry(() => {
257+
ns.inProgressContainerNumByNamespace shouldBe 0
258+
ns.existingContainerNumByNamespace shouldBe 0
259+
}, 10, Some(100.milliseconds))
259260

260261
val invoker = "invoker0"
261262
(0 to 100).foreach(i => {
@@ -271,9 +272,10 @@ class ContainerCounterTests
271272
"test-value")
272273
})
273274

274-
Thread.sleep(5000)
275-
ns.inProgressContainerNumByNamespace shouldBe 101
276-
ns.existingContainerNumByNamespace shouldBe 101
275+
retry(() => {
276+
ns.inProgressContainerNumByNamespace shouldBe 101
277+
ns.existingContainerNumByNamespace shouldBe 101
278+
}, 50, Some(100.milliseconds))
277279
}
278280

279281
class MockEtcdClient(client: Client, isLeader: Boolean, leaseNotFound: Boolean = false, failedCount: Int = 0)

0 commit comments

Comments
 (0)