Skip to content

Commit

Permalink
Bulk CDK: ConnectorRunner accepts explicit isTest flag (#46920)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgao authored Oct 17, 2024
1 parent f541352 commit 55a7522
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ sealed class AirbyteConnectorRunner(
val testBeanDefinitions: Array<out RuntimeBeanDefinition<*>>,
val testProperties: Map<String, String> = emptyMap(),
) {
val envs: Array<String> = arrayOf(Environment.CLI, connectorType)
// Micronaut's TEST env detection relies on inspecting the stacktrace and checking for
// any junit calls. This doesn't work if we launch the connector from a different thread, e.g.
// `Dispatchers.IO`. Force the test env if needed. (Some tests launch the connector from the IO
// context to avoid blocking themselves.)
private val isTest = testBeanDefinitions.isNotEmpty()
val envs: Array<String> =
arrayOf(Environment.CLI, connectorType) +
if (isTest) {
arrayOf(Environment.TEST)
} else {
emptyArray()
}

inline fun <reified R : Runnable> run() {
val picocliCommandLineFactory = PicocliCommandLineFactory(this)
Expand All @@ -82,6 +93,10 @@ sealed class AirbyteConnectorRunner(
)
.beanDefinitions(*testBeanDefinitions)
.start()
// We can't rely on the isTest value from our constructor,
// because that won't autodetect junit in our stacktrace.
// So instead we ask micronaut (which will include if we explicitly added
// the TEST env).
val isTest: Boolean = ctx.environment.activeNames.contains(Environment.TEST)
val picocliFactory: CommandLine.IFactory = MicronautFactory(ctx)
val picocliCommandLine: CommandLine =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data object CliRunner {
args,
testProperties,
inputBeanDefinition,
out.beanDefinition
out.beanDefinition,
)
}
return CliRunnable(runnable, out.results)
Expand Down

0 comments on commit 55a7522

Please sign in to comment.