Skip to content

Added CheckLibraryVersion class for check library version#142

Merged
polischuks merged 7 commits intohyperskill:masterfrom
polischuks:HSPC-70
Jun 12, 2023
Merged

Added CheckLibraryVersion class for check library version#142
polischuks merged 7 commits intohyperskill:masterfrom
polischuks:HSPC-70

Conversation

@polischuks
Copy link
Copy Markdown
Contributor

Task: #HSPC-70

Dependencies

  • !

Reviewers

Description

@aaaaaa2493
Copy link
Copy Markdown

Please, don't add unnecessary dependencies to the hs-test. There is gson dependency to work with JSON, use it instead.

@Test
public final void start() {
CheckLibraryVersion checkLibraryVersion = new CheckLibraryVersion();
checkLibraryVersion.checkVersion();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Every executable code of hs-test should be under try-catch block. Including this one. It guarantees that in case something goes wrong, the user would still get some message from testing (yes, it would be Unexpected error but it is better than just crash with exception)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, why do we even need to check the library beforehand if we use this information only in case the user failed test? We should check the version only in case of fail as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have two variants to check,
if (!currentVersion.equals(latestVersion)) { if (currentVersion.split("\\.")[0] != latestVersion.split("\\.")[0]) { throw new RuntimeException(getFeedback()); } else { isLatestVersion = false; } }
if (currentVersion.split("\\.")[0] != latestVersion.split("\\.")[0]) { throw new RuntimeException(getFeedback());
if the user's version and Git do not equal in main index X.0.0 user has RuntimeException(getFeedback()); and process stoped,
and light checking when the user has failed on the test case.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What kind of feature should it be for the release of (X+1).0.0 so that every user needs to update to it right now? Every major release added support for major technology or language. For example: support of Go testing, support of Bash testing, support of Spring Boot testing. In case the users already testing their applicarion chances are that they simply don't need new major language or technology supported in hs-test. Because whatever they are testing already supported in hs-test.


int responseCode = connection.getResponseCode();
if (responseCode != 200) {
throw new UnexpectedError("Error getting latest version of hs-test library from GitHub");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok, in case GitHub is down our users can't even test their code. It is not OK. I think, in case we can't check library version, you should assume it's the latest version.

Copy link
Copy Markdown

@aaaaaa2493 aaaaaa2493 May 18, 2023

Choose a reason for hiding this comment

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

Also, keep in mind that online checking (from the website) is done in the isolated environment and there are no internet connection. Such way of checking should continue working fine. We should not rely on internet being accessible while checking user code. Could you please tell what is a motivation behind this issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you mean that with online verification it will not be possible to get the current version in GitHub, the latestVersion will be equal to the currentVersion and the user will continue to work with tests.
The relevance of the library to work in images for online verification is not the task of the user, we must maintain the relevance of the library for online verification.

Copy link
Copy Markdown

@aaaaaa2493 aaaaaa2493 May 19, 2023

Choose a reason for hiding this comment

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

@polischuks Yes. But online checking in done without access to the internet (Docker image has no access to he internet) and that is why the check will fail. That's what I mean

@polischuks
Copy link
Copy Markdown
Contributor Author

@aaaaaa2493
fixed:

  • uses Gson
  • added: if getting response from GitHub is crashing, latestVersion=currentVersion

@aaaaaa2493
Copy link
Copy Markdown

@polischuks please remove the following from the dependencies

implementation 'javax.json:javax.json-api:1.1.4'
implementation 'org.glassfish:javax.json:1.1.4'

@polischuks polischuks requested a review from aaaaaa2493 May 23, 2023 06:09
lastChecked = LocalDate.parse(reader.readLine());
reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
Copy link
Copy Markdown

@aaaaaa2493 aaaaaa2493 May 23, 2023

Choose a reason for hiding this comment

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

Why this method contains a lot of RuntimeException's? That's not a good way of handling checked exceptions making them unchecked exceptions. At the very least they should be UnexpectedError's. Or just make the method as thorows IOException

@polischuks
Copy link
Copy Markdown
Contributor Author

@aaaaaa2493 fixed

reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
throw new IOException(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's basically the same as in throwing RuntimeException. You can just omit catch block, it's useless

writer.write(lastChecked.toString());
} catch (IOException e) {
throw new RuntimeException(e);
throw new IOException(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same

@polischuks
Copy link
Copy Markdown
Contributor Author

@aaaaaa2493 fixed/ removed catch blocks

@polischuks polischuks requested a review from aaaaaa2493 May 23, 2023 19:59
}
}

if (lastChecked != null && lastChecked.equals(LocalDate.now())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (lastChecked != null && lastChecked.equals(LocalDate.now())) {
if (LocalDate.now().equals(lastChecked)) {

private void getLatestHsTestVersionFromGitHub() {
HttpURLConnection connection = null;
try {
URL url = new URL("https://api.github.com/repos/hyperskill/hs-test/releases/latest");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check timeout

*/
public void checkVersion() throws IOException {
LocalDate lastChecked = null;
File lastCheckedFile = new File("LastChecked.txt");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check what this file doesn't put into submission.

@polischuks polischuks requested a review from meanmail June 6, 2023 15:51
@polischuks polischuks merged commit 94a1452 into hyperskill:master Jun 12, 2023
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