Skip to content

Commit

Permalink
MiskApplication tests should await ServiceManager Healthy
Browse files Browse the repository at this point in the history
before proceeding

GitOrigin-RevId: 616c6bb2e1520d114759259e2c0285a393942f50
  • Loading branch information
ericloe-cash authored and svc-squareup-copybara committed Oct 28, 2024
1 parent 30ab5fa commit 8693bc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package misk.web.health
import ch.qos.logback.classic.Level.INFO
import ch.qos.logback.classic.Logger
import com.google.common.util.concurrent.AbstractIdleService
import com.google.common.util.concurrent.ServiceManager
import com.google.inject.util.Modules
import jakarta.inject.Inject
import jakarta.inject.Singleton
Expand Down Expand Up @@ -152,6 +153,10 @@ class MiskApplicationHealthServiceTest {
get(healthReadinessUrl, "health", expectThrowable = ConnectException::class)
get(healthStatusUrl, "health", expectThrowable = ConnectException::class)

// Make sure all services are up before proceeding.
val serviceManager = miskApplication.injector.getInstance(ServiceManager::class.java)
serviceManager.awaitHealthy()

// Health service will start after all running services so allow it to start.
DelayHealthStart.okToStartUp.countDown()
sleep(5.seconds.inWholeMilliseconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ch.qos.logback.classic.Logger
import com.google.common.util.concurrent.AbstractIdleService
import com.google.common.util.concurrent.Service
import com.google.common.util.concurrent.Service.State.NEW
import com.google.common.util.concurrent.ServiceManager
import jakarta.inject.Inject
import jakarta.inject.Singleton
import misk.MiskApplication
Expand Down Expand Up @@ -592,6 +593,12 @@ class GracefulShutdownInterceptorTest {
}

JettyStartedService.startedLatch.await(10, TimeUnit.SECONDS)

// Now that we know serviceManager is created and running make sure all services are healthy
// before proceeding.
val serviceManager = miskApplication.injector.getInstance(ServiceManager::class.java)
serviceManager.awaitHealthy()

return miskApplication
}

Expand Down

0 comments on commit 8693bc5

Please sign in to comment.