Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
praveek committed Jun 3, 2024
1 parent 59c5ed5 commit 65b0fd9
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import java.lang.UnsupportedOperationException
import java.util.Locale
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -148,6 +149,23 @@ internal class EventHubTests {
}
}

private class TestExtension_InitCallback(api: ExtensionApi) : Extension(api) {
companion object {
const val EXTENSION_NAME = "TestExtension_InitCallback"

// Calls this during initialization
var initCallback: (() -> Unit)? = null
}

init {
initCallback?.invoke()
}

override fun getName(): String {
return EXTENSION_NAME
}
}

private lateinit var eventHub: EventHub
private val eventType = "Type"
private val eventSource = "Source"
Expand Down Expand Up @@ -199,6 +217,26 @@ internal class EventHubTests {
assertEquals(EventHubError.None, ret)
}

@Test
fun testExecutionOrderBeforeExtensionInitialization() {
val latch = CountDownLatch(1)
val flag = AtomicBoolean(false)
TestExtension_InitCallback.initCallback = {
if (flag.get()) {
latch.countDown()
}
}

// This should complete before the extension instance is created.
eventHub.executeInEventHubExecutor {
flag.set(true)
}
val ret = registerExtension(TestExtension_InitCallback::class.java)
assertEquals(EventHubError.None, ret)

assertTrue { latch.await(250, TimeUnit.MILLISECONDS) }
}

@Test
fun testRegisterExtensionFailure_DuplicateExtension() {
var ret = registerExtension(TestExtension2::class.java)
Expand Down

0 comments on commit 65b0fd9

Please sign in to comment.