Skip to content

Commit 247db36

Browse files
committed
fix flaky test, clean up netty warning logs
1 parent 6791adb commit 247db36

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

java-plugin/src/main/kotlin/io/github/danielpeach/plugin/Broker.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class Broker internal constructor(
7272
* @param [services] The gRPC services that the [Broker] should serve.
7373
*
7474
* @returns [Server] A gRPC server that implements the provided [services].
75-
*
76-
* @throws [BrokerServiceException]
7775
* */
7876
fun acceptAndServe(serviceId: Int, vararg services: BindableService): Server = runBlocking(scope.coroutineContext) {
7977
val server = channelProvider.server("unix", *services).start()
@@ -112,7 +110,7 @@ class Broker internal constructor(
112110
stub
113111
.startStream(sender.consumeAsFlow())
114112
.catch { e ->
115-
sender.cancel(BrokerServiceException(e))
113+
sender.cancel(CancellationException(e))
116114
}
117115
.collect { connection ->
118116
logger.debug("Received connection info for service #${connection.serviceId}")

java-plugin/src/main/kotlin/io/github/danielpeach/plugin/BrokerServiceException.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

java-plugin/src/main/kotlin/io/github/danielpeach/plugin/ChannelProvider.kt

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.grpc.Server
66
import io.grpc.netty.GrpcSslContexts
77
import io.grpc.netty.NettyChannelBuilder
88
import io.grpc.netty.NettyServerBuilder
9+
import io.netty.channel.ChannelOption
910
import io.netty.channel.epoll.EpollDomainSocketChannel
1011
import io.netty.channel.epoll.EpollEventLoopGroup
1112
import io.netty.channel.epoll.EpollServerDomainSocketChannel
@@ -36,24 +37,27 @@ internal class ChannelProvider(private val mTLSConfig: MTLSConfig? = null) {
3637
throw IllegalArgumentException("Network type '$network' is not supported.")
3738
}
3839

39-
val (builder, shutdownHook) = when (val os = System.getProperty("os.name")) {
40+
val builder = NettyChannelBuilder.forAddress(DomainSocketAddress(address))
41+
.withOption(ChannelOption.SO_KEEPALIVE, null)
42+
43+
val shutdownHook = when (val os = System.getProperty("os.name")) {
4044
MAC_OS -> {
4145
val kqg = KQueueEventLoopGroup()
42-
val builder =
43-
NettyChannelBuilder.forAddress(DomainSocketAddress(address))
44-
.eventLoopGroup(kqg)
45-
.channelType(KQueueDomainSocketChannel::class.java)
4646

47-
builder to { kqg.shutdownGracefully() }
47+
builder
48+
.eventLoopGroup(kqg)
49+
.channelType(KQueueDomainSocketChannel::class.java);
50+
51+
{ kqg.shutdownGracefully() }
4852
}
4953
LINUX -> {
5054
val elg = EpollEventLoopGroup()
51-
val builder =
52-
NettyChannelBuilder.forAddress(DomainSocketAddress(address))
53-
.eventLoopGroup(elg)
54-
.channelType(EpollDomainSocketChannel::class.java)
5555

56-
builder to { elg.shutdownGracefully() }
56+
builder
57+
.eventLoopGroup(elg)
58+
.channelType(EpollDomainSocketChannel::class.java);
59+
60+
{ elg.shutdownGracefully() }
5761
}
5862
else -> throw IllegalArgumentException("OS '$os' is not supported.")
5963
}
@@ -103,18 +107,20 @@ internal class ChannelProvider(private val mTLSConfig: MTLSConfig? = null) {
103107
throw IllegalArgumentException("Network type '$network' is not supported.")
104108
}
105109

106-
val (builder, shutdownHook) = when (val os = System.getProperty("os.name")) {
110+
val builder = NettyServerBuilder.forAddress(DomainSocketAddress(address))
111+
.withChildOption(ChannelOption.SO_KEEPALIVE, null)
112+
113+
val shutdownHook = when (val os = System.getProperty("os.name")) {
107114
MAC_OS -> {
108115
val boss = KQueueEventLoopGroup()
109116
val worker = KQueueEventLoopGroup()
110117

111-
val builder =
112-
NettyServerBuilder.forAddress(DomainSocketAddress(address))
113-
.bossEventLoopGroup(boss)
114-
.workerEventLoopGroup(worker)
115-
.channelType(KQueueServerDomainSocketChannel::class.java)
118+
builder
119+
.bossEventLoopGroup(boss)
120+
.workerEventLoopGroup(worker)
121+
.channelType(KQueueServerDomainSocketChannel::class.java);
116122

117-
builder to {
123+
{
118124
boss.shutdownGracefully()
119125
worker.shutdownGracefully()
120126
}
@@ -123,13 +129,12 @@ internal class ChannelProvider(private val mTLSConfig: MTLSConfig? = null) {
123129
val boss = EpollEventLoopGroup()
124130
val worker = EpollEventLoopGroup()
125131

126-
val builder =
127-
NettyServerBuilder.forAddress(DomainSocketAddress(address))
128-
.bossEventLoopGroup(boss)
129-
.workerEventLoopGroup(worker)
130-
.channelType(EpollServerDomainSocketChannel::class.java)
132+
builder
133+
.bossEventLoopGroup(boss)
134+
.workerEventLoopGroup(worker)
135+
.channelType(EpollServerDomainSocketChannel::class.java);
131136

132-
builder to {
137+
{
133138
boss.shutdownGracefully()
134139
worker.shutdownGracefully()
135140
}

java-plugin/src/test/kotlin/io/github/danielpeach/plugin/BrokerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class BrokerTest : JUnit5Minutests {
4646
}
4747
}
4848

49-
test("acceptAndServe throws a BrokerServiceException when the broker server is not running") {
49+
test("acceptAndServe throws a CancellationException when the broker server is not running") {
5050
// Client
5151
brokerClient.start()
5252

5353
// Server
5454
brokerServer.shutdownAndAwait()
5555

5656
val serviceId = brokerClient.getNextId()
57-
expectThrows<BrokerServiceException> {
57+
expectThrows<CancellationException> {
5858
brokerClient.acceptAndServe(serviceId, TestService())
5959
}
6060
}

java-plugin/src/test/kotlin/io/github/danielpeach/plugin/ControllerTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ControllerTest : JUnit5Minutests {
1818

1919
after {
2020
if (!controllerServer.isShutdown) {
21-
controllerServer.shutdown()
21+
controllerServer.shutdownAndAwait()
2222
}
2323
}
2424

@@ -62,8 +62,7 @@ class ControllerTest : JUnit5Minutests {
6262
.start()
6363
.also { server ->
6464
controllerService.shutdownHook = {
65-
server.shutdownNow()
66-
server.awaitTermination()
65+
server.shutdownAndAwait()
6766
}
6867
}
6968

0 commit comments

Comments
 (0)