Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add connection timeout; remove legacy jenkins adapter #641

Merged
merged 6 commits into from
May 6, 2021

Conversation

skaldarnar
Copy link
Member

@skaldarnar skaldarnar commented May 6, 2021

This PR removes the legacy Jenkins adapter (for jenkins.terasology.org) as we've shut it down recently.

In addtion, it improves the handling of unavailable resources by introducing a 10 second timeout for the
connections in JenkinsClient. This will improve offline usage of the launcher, as well as cases where
the new Jenkins instance is not available.

  • fix: add connection timeout of 10 seconds to JenkinsClient
  • feat: show info label in splash screen when fetching game releases
  • perf: fetch releases in parallel
  • chore: remove LegacyJenkinsRepositoryAdapter
  • test: remove tests for legacy jenkins adapter
  • test: adjust tests for JenkinsClient

ℹ️ Please merge-commit or keep all commit messages when squash-merging.

Closes #640.

This introduces a new translation key `splash_fetchReleases`.
Fetching available releases from independent sources should be independent of each other. Thus, we
can run this in parallel by using a `parallelStream()`.
The legacy Jenkins instance (`jenkins.terasology.org`) is no longer available. Therefore, we don't
need this repository adapter anymore.

Closes #640
@skaldarnar skaldarnar added Type: Bug Bug reports for launcher releases (reproducible from master) Type: Maintenance Maintenance or chores not adding new features or fixing bugs. labels May 6, 2021
@skaldarnar
Copy link
Member Author

After merging this we should make a new bugfix release and notify the user who reported the issue on reddit.

Cervator
Cervator previously approved these changes May 6, 2021
This also makes the JenkinsClient testable again by making the `openStream` utility method a static
 member. This allows to stub only that static method for testing, while keeping the class-under-test
 untouched.
return gson.fromJson(reader, Jenkins.ApiResult.class);
} catch (JsonSyntaxException | JsonIOException e) {
logger.warn("Failed to read JSON from '{}'", url.toExternalForm(), e);
} catch (IOException e) {
logger.warn("Failed to read from URL: {}", url.toExternalForm(), e);
logger.warn("Failed to read from URL '{}'\n\t{}", e.getMessage(), url.toExternalForm());
Copy link
Member

Choose a reason for hiding this comment

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

I think you've gotten the argument order swapped here. You still want the url first,
and then if you want to just do e.getMessage() instead of the logger's default exception formatter, that's your second argument.

Copy link
Member

Choose a reason for hiding this comment

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

(also, if you find yourself avoiding the logger's default exception formatter often, that could be a sign that we should reconfigure the logger)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I'm actually not sure about best logging patterns. If you happen to know good resources on that let me know 🤓

The arguments are actually in the order I want them to be. The message is usually short and descriptive, so you can see what's wrong directly. The URL is pretty lengthy (maybe another option would be to drop the query parameters?), that's I wanted to move that to second line. Just forgot to adjust the text itself to reflect that.

On changing the default exception formatter: I do think that logging a full stack trace is only appropriate if we expect this is needed for investigating the issue, and/or if this is fatal error we cannot recover from. In this case, an exception here is unfortunate, but can happen for various reasons. Usually the stacktrace does not give helpful info here, but clutters the log.

Copy link
Member

Choose a reason for hiding this comment

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

ah, I didn't expect the URL to be that long, but that would explain it

Copy link
Member Author

Choose a reason for hiding this comment

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

For reference the full URL with search query parameters:

http://jenkins.terasology.io/teraorg/job/Terasology/job/Omega/job/master/api/json?tree=builds[number,timestamp,result,artifacts[fileName,relativePath],url]

Consisting of the base URL

http://jenkins.terasology.io/

followed by the job descriptor

/teraorg/job/Terasology/job/Omega/job/master

and finally a filtered view on the data

/api/json?tree=builds[number,timestamp,result,artifacts[fileName,relativePath],url]

So yeah, it's pretty lengthy 😅

@@ -157,3 +157,4 @@ update_game_extractZip=Spiel-Datei entpacken ...
update_game_gameInfo=Spiel-Informationen aktualisieren ...
update_game_startDownload=Spiel herunterladen ...
update_launcher_updateFailed=Launcher-Aktualisierung fehlgeschlagen!
splash_fetchReleases=Rufe verügbare Spiele ab ...
Copy link
Member

Choose a reason for hiding this comment

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

👍 remembering to update the translation catalog!

Comment on lines +52 to +53
try (MockedStatic<JenkinsClient> utilities = Mockito.mockStatic(JenkinsClient.class)) {
utilities.when(() -> JenkinsClient.openStream(urlToInvalidPayload)).thenReturn(invalidPayload);
Copy link
Member

Choose a reason for hiding this comment

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

This is a little different than the other mockito usages I've seen. Is it because it's a static function, and mocking those works differently?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, exactly. I was looking at https://www.baeldung.com/mockito-mock-static-methods for reference.

I feel uneasy to mock (parts of) the unit under test, and using a static method that I can stub separately looked like a good compromise to keep the test.

@skaldarnar skaldarnar merged commit ec9c091 into master May 6, 2021
@skaldarnar skaldarnar deleted the fix/delayed-by-unavailable-resources branch May 6, 2021 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports for launcher releases (reproducible from master) Type: Maintenance Maintenance or chores not adding new features or fixing bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove legacy repository server
3 participants