Skip to content

Conversation

lauzadis
Copy link
Contributor

Issue #

Description of changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lauzadis lauzadis marked this pull request as ready for review November 19, 2024 16:12
@lauzadis lauzadis requested a review from a team as a code owner November 19, 2024 16:12
Comment on lines +105 to +106
if not opts.no_system_certs:
cmd.append(f'-v/etc/ssl:/etc/ssl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: f is unnecessary since we're not formatting any parameters in this string

Comment on lines 22 to 21
protected val serverPort: Int = ServerSocket(0).use { it.localPort }
protected val serverPort: Int = 54734
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: This will conflict if any other process (including a parallel build of this package in another workspace) is using port 54734. Is there a reason why it's necessary to use a static port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't configure a port, it will default to 80, we could make it a randomly selected port if you think that will be safer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random ports are marginally safer but still could conflict with an open port. I think we can still bind to an available address using Ktor's low-level KMP socket interfaces:

protected val serverPort: Int = runBlocking {
    SelectorManager(coroutineContext).use { selector ->
        aSocket(selector)
            .tcp()
            .bind()
            .use { (it.localAddress as InetSocketAddress).port }
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this works great

Comment on lines 32 to 44
attempt++
try {
server.start()
println("test server listening on: $testHost:$serverPort")
break
} catch (cause: Throwable) {
if (attempt >= 10) throw cause
Thread.sleep(250L * attempt)
delay(250L * attempt)
}
} while (true)

ensureServerRunning()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Isn't server.start() asynchronous? Won't removing ensureServerRunning() mean that it's possible to return from this method before the server is actually running?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I refactored this to use ktor's monitoring API. I was having trouble with a KMP solution to ensureServerRunning by making a request.

Comment on lines 22 to 23
crc.update(input.encodeToByteArray(), 0, input.length)
assertEquals(2666930069U, crc.digestValue()) // checksum of "foobar"
assertEquals("nvYflQ==", crc.digest().encodeBase64String())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why are we moving the digestValue checks from these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our current JVM implementation of digestValue() does not reset the checksum and these tests were depending on that faulty behavior (calling digestValue() then digest() immediately after).

I've clarified the behavior in KDocs and also updated our JVM implementation. Let me know if you think we should keep the existing (arguably broken) behavior. KotlinNative / CRT will likely be unable to match that behavior though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. If this was already broken behavior then you're probably right.

Comment on lines +55 to +63
def shell(command, cwd=None, check=True, capture_output=False):
"""
Run a command
:param command: command to run
:param cwd: the current working directory to change to before executing the command
:param check: flag indicating if the status code should be checked. When true an exception will be
thrown if the command exits with a non-zero exit status.
:returns: the subprocess CompletedProcess output
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Docs are missing for capture_output

@lauzadis lauzadis merged commit 523dba9 into kn-main Dec 17, 2024
8 of 11 checks passed
lauzadis added a commit that referenced this pull request Jan 6, 2025
@lauzadis lauzadis deleted the kn-checksums branch January 30, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants