And another curious question about KTor sockets, a...
# ktor
r
And another curious question about KTor sockets, apart from the apparently non-existing timeout, how am I supposed to test sockets in a reasonable way? Seems the only way I can find is to wrap the static methods in interfaces so, I can inject test-implementations - but I assume that KTor sockets isn't designed in the non-testable fashions that 10+ years of programming experience have shown us to be bad design?
a
Could you please describe your test scenario?
r
In this case, I basically want to ensure that the socket attempts to connect to a certain IP and port in this case, so I'd like to do something along the lines of (in semi pseudo code):
Copy code
val testKtor = TODO()
val myService = Service(testKtor)

val host = Host("127.0.0.1", 22)
myService.perform(host)

testKtor.connections.shouldHaveSize(1)
val connection = testKtor.connections[0]
connection.type = ConnectionTypes.TCP
connection.host.shouldBe("127.0.0.1")
connection.post.shouldBe(22)
(whether it be exactly like that or not doesn't matter, it's more that I can test that it respects the parameters - preferrably in a way that's independent on if I call
.connect(host, port)
,
.connect(SocketAddress(...))
or something else)
a
Unfortunately, there are no such inspection capabilities in Ktor so you have to write a wrapper around Ktor’s API.