Skip to content

Conversation

@sunkup
Copy link
Member

@sunkup sunkup commented Nov 19, 2025

#82 changed the implementation of getSiteCertificates.

The new getSiteCertificates implementation (now in the unit test) creates an SSLSocket and calls startHandshake() with no connect/read timeouts, so we get infinite run time in CI.

To fix this, this PR

  • moves TestCertStore to separate file
  • adds timeouts to the certificate retrieval

@sunkup sunkup linked an issue Nov 19, 2025 that may be closed by this pull request
@sunkup sunkup self-assigned this Nov 19, 2025
@sunkup sunkup added the bug Something isn't working label Nov 19, 2025
@sunkup sunkup marked this pull request as ready for review November 19, 2025 11:44
@sunkup sunkup requested a review from a team as a code owner November 19, 2025 11:44
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

A timeout looks like a good idea, but a socket should have reasonable default timeouts (not infinite). Is this really the cause of the problem?

I see that in #82 the conn.inputStream.read() (which guarantees that the connection is established) of the HttpUrlConnection was replaced by sslSocket.startHandshake(). Do we need this change and can it be related? In the original code, we didn't have to create a socket manually.

Or in other words: can we change it back to conn.inputStream.read() and it works again?

@sunkup
Copy link
Member Author

sunkup commented Nov 19, 2025

Or in other words: can we change it back to conn.inputStream.read() and it works again?

Yes, that should also work. I just wanted to get rid of the deprecations while at it. I think it should work like this, but would you like me to change it back?

@rfc2822
Copy link
Member

rfc2822 commented Nov 19, 2025

Yes, that should also work. I just wanted to get rid of the deprecations while at it. I think it should work like this, but would you like me to change it back?

It just looks like a much easier solution that doesn't cause extra work (like thinking about sockets and timeouts), so instead of adding more code, yes, I'd prefer the single-line solution, especially because it's only a helper for testing. For production code I'd avoid HttpUrlConnection.

There shouldn't be a deprecation of read? Or do you mean the whole HttpUrlConnection which is deprecated? I think we can keep it in the test helper. Otherwise we can replace it by okhttp at some time if the UrlConnection is really dropped.

@sunkup sunkup marked this pull request as draft November 19, 2025 13:47
@sunkup sunkup marked this pull request as ready for review November 19, 2025 14:20
@sunkup sunkup requested review from Copilot and rfc2822 November 19, 2025 14:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an infinite runtime issue in CI caused by a previous change to getSiteCertificates. The fix involves adding connect and read timeouts to certificate retrieval and refactoring the test code structure.

  • Extracts TestCertStore class into a separate test file for better organization
  • Replaces the SSLSocket-based certificate retrieval with HttpsURLConnection that includes 5-second timeouts
  • Simplifies certificate retrieval logic while maintaining test functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
TestCertStore.kt New file containing the extracted TestCertStore test implementation, previously embedded in CustomCertManagerTest.kt
CustomCertManagerTest.kt Refactored getSiteCertificates method to use HttpsURLConnection with timeouts instead of raw SSLSocket; removed TestCertStore class and unused imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rfc2822
Copy link
Member

rfc2822 commented Nov 19, 2025

Tests are failing, resetting to draft

@rfc2822 rfc2822 marked this pull request as draft November 19, 2025 16:14
@sunkup sunkup removed the request for review from rfc2822 November 20, 2025 08:29
@sunkup sunkup force-pushed the 83-instrumented-tests-run-for-infinite-time branch from b0863be to 9f59985 Compare November 20, 2025 08:47
@sunkup
Copy link
Member Author

sunkup commented Nov 20, 2025

Sorry about that. I think calling getSiteCertificates() as soon as the class is loaded made it hang forever in CI only, because it worked just fine locally. I moved it to @BeforeClass in the companion object which is probably cleaner anyways.

@sunkup sunkup marked this pull request as ready for review November 20, 2025 09:28
@sunkup sunkup requested a review from rfc2822 November 20, 2025 09:28
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Minor suggestions

@sunkup sunkup requested a review from rfc2822 November 20, 2025 10:53
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Nice 👍🏻

@sunkup sunkup merged commit 58998ba into main Nov 20, 2025
5 checks passed
@sunkup sunkup deleted the 83-instrumented-tests-run-for-infinite-time branch November 20, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instrumented tests run for infinite time

2 participants