testcontainers / testcontainers/testcontainers-java

Use Executor in AbstractWaitStrategy

Open
#5,253 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

I am trying to bridge to a suspend version of waitUntilReady in AbstractWaitStrategy with something along the lines of:

suspend fun strategy(waitingStrategyTarget: WaitingStrategyTarget): Unit {
  // run your strategy
}

class MyWaitStrategy : AbstractWaitStrategy() {
  override fun waitUntilReady() {
    val executor: ExecutorService = EXECUTOR // executor from  AbstractWaitStrategy
    runBlocking(executor.asCoroutineDispatcher()) {
      strategy(waitingStrategyTarget)
    }
  }
}

or in a TestScope with JUnit this may look like:

@Test
    fun testWithSuspendedWaitStrategy() = 
      runTest {
        val strategy = 
            waitStrategy { target -> 
               // run my strategy
            }

       // MyContainer.waitUntil(strategy, ....)
      }

fun TestScope.waitStrategy(
  f: CoroutineScope.(target: WaitStrategyTarget) -> Unit
): AbstractWaitStrategy =
  object : AbstractWaitStrategy() {
    override fun waitUntilReady() {
      launch(EXECUTOR.asCoroutineDispatcher()) {
        f(this, waitStrategyTarget)
      }
    }
  }

Is there a way how to implement this with EXECUTOR, being public instead of package private, or with another Executor, ExecutorService or something.

Any Feedback is welcome :D

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading core/src/main/java/org/testcontainers/containers/wait/strategy/AbstractWaitStrategy.java, especially the EXECUTOR declaration and waitUntilReady integration. The issue provides Kotlin coroutine examples but no named tests or acceptance criteria; a completed change would need an agreed approach for exposing or replacing the executor and a defined way to verify suspended wait strategies.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.