diff --git a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt
index 5f7d9bed7f..f89c6c173e 100644
--- a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt
+++ b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt
@@ -68,6 +68,7 @@ private fun getTimestampAsDirectoryName(): String {
class DriverHandle(private val driverDsl: DriverDSL, private val shutdownHook: Thread) {
val messagingService = driverDsl.messagingService
+ val networkMapCache = driverDsl.networkMapCache
fun waitForAllNodesToFinish() {
driverDsl.waitForAllNodesToFinish()
@@ -79,7 +80,7 @@ class DriverHandle(private val driverDsl: DriverDSL, private val shutdownHook: T
}
}
-private fun poll(f: () -> A?): A {
+fun poll(f: () -> A?): A {
var counter = 0
var result = f()
while (result == null && counter < 30) {
diff --git a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt
new file mode 100644
index 0000000000..1c34558226
--- /dev/null
+++ b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt
@@ -0,0 +1,48 @@
+package com.r3corda.node.driver
+
+import com.r3corda.node.services.messaging.ArtemisMessagingService
+import com.r3corda.node.services.transactions.NotaryService
+import org.junit.Test
+import java.net.Socket
+import java.net.SocketException
+
+
+class DriverTests {
+
+ @Test
+ fun simpleNodeStartupShutdownWorks() {
+
+ // Start a notary
+ val (handle, notaryNodeInfo) = driver(quasarPath = "../lib/quasar.jar") {
+ startNode(setOf(NotaryService.Type), "TestNotary")
+ }
+ // Check that the node is registered in the network map
+ poll {
+ handle.networkMapCache.get(NotaryService.Type).firstOrNull {
+ it.identity.name == "TestNotary"
+ }
+ }
+ // Check that the port is bound
+ val address = notaryNodeInfo.address as ArtemisMessagingService.Address
+ poll {
+ try {
+ Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()
+ Unit
+ } catch (_exception: SocketException) {
+ null
+ }
+ }
+
+ // Shutdown
+ handle.shutdown()
+ // Check that the port is not bound
+ poll {
+ try {
+ Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()
+ null
+ } catch (_exception: SocketException) {
+ Unit
+ }
+ }
+ }
+}