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

Gitlab container and tests #1335

Merged
merged 39 commits into from
Sep 18, 2023
Merged

Conversation

ampuscas
Copy link
Contributor

Testing done

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

pom.xml Outdated
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.11</version>
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason you aren't using the built-in Java HttpClient?
https://www.baeldung.com/java-9-http-client

this avoids adding another dependency, either way probably shouldn't be using an alpha one

Copy link
Contributor

Choose a reason for hiding this comment

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

I switched this over to using java HttpClient. There seems to be lots of configuration options for the java http client, please let me know if you think there is one we should have that I am missing.

I really appreciate your feedback and support with this @timja 😃

Copy link
Contributor

@raul-arabaolaza raul-arabaolaza left a comment

Choose a reason for hiding this comment

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

Leave several comments

Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this mapping?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment resolved due to switching over to java http client

return response;
}

public void deleteRepo(String token) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void deleteRepo(String token) throws IOException {
public void deleteRepo(String repo) throws IOException {

You do not need the token as there is a getter for it, but you should not assume there is only one repo...

ProjectApi projApi = new ProjectApi(gitlabapi);

try {
Project project = projApi.getProjects().get(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if more than one test is running in parallel? There will be more than one repo

}
}

public String createUserToken() throws IOException, InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public String createUserToken() throws IOException, InterruptedException {
public String createUser(String username) throws IOException, InterruptedException {

Copy link
Contributor

Choose a reason for hiding this comment

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

This should allow you to create any user you want and return the token for further auth if needed

@@ -0,0 +1,13 @@
user = User.create();
user.name = 'test';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hardcoded, what if this is called by tests in parallel? Is gonna fail. Maybe you can try what is described here https://www.codecademy.com/article/ruby-command-line-argv

Copy link
Member

Choose a reason for hiding this comment

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

what if this is called by tests in parallel

then each test should have its own instance of the container so it doesn't matter (unless we are running multiple tests in the same JVM at once which we are not (threading as opposed to forking))

user = User.create();
user.name = 'test';
user.username = 'test';
user.password = 'oparolaoarecare12!';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before, this should be an argument comming from the java call

user.password = 'oparolaoarecare12!';
user.confirmed_at = '01/01/1990';
user.admin = true;
user.email = '$test@example.com';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

.github/renovate.json Outdated Show resolved Hide resolved
pom.xml Outdated
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.11</version>
</dependency>
Copy link
Contributor

@julieheard julieheard Aug 21, 2023

Choose a reason for hiding this comment

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

Ignore that this is in here twice - we have Andra and I working on the same PR so just caught in the crossfire. We are removing as moving to http client shortly so ignore for now 🙂

try {
Project project = projApi.getProjects().get(0);
projApi.deleteProject(project.getId());
} catch (GitLabApiException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to wrap inside a RuntimeException just throw it and the test will fail if thrown

@ampuscas ampuscas marked this pull request as ready for review August 22, 2023 09:18
Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

Should this be in draft until there is a test that exercises some functionality in Jenkins provided by the GitLab plugin?

public HttpResponse<String> createRepo(String repoName, String token) throws IOException {
try{
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://" + getIpAddress() + "/api/v4/projects"))
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 this will not work in all scenarious - the web port has not been configured as exposed (@DockerFixture(id = "gitlab-plugin", ports = 22)) and as such you may not be able to communicate witht the web interface of GitLab depending on your docker setup. IIUC you should add a new mapping for the web port.

Additionally you have getURL() that you should call to then addon the endpoint rather than repeating yourself.


public URL getURL() throws IOException {
// return new URL("http://" + host() + ":" + port());
return new URL("http://" + getIpAddress());
Copy link
Member

Choose a reason for hiding this comment

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

you need to use the ipaddress and port that is mapped here.

@@ -0,0 +1,13 @@
user = User.create();
user.name = 'test';
Copy link
Member

Choose a reason for hiding this comment

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

what if this is called by tests in parallel

then each test should have its own instance of the container so it doesn't matter (unless we are running multiple tests in the same JVM at once which we are not (threading as opposed to forking))

.until( () -> {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://" + getIpAddress()))
Copy link
Member

Choose a reason for hiding this comment

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

use getURL()

public void waitForReady(CapybaraPortingLayer p) {
int timeout = (int) time.milliseconds(200000);
p.waitFor().withMessage("Waiting for GitLab to come up")
.withTimeout(Duration.ofSeconds(timeout)) // GitLab starts in about 2 minutes
Copy link
Member

Choose a reason for hiding this comment

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

would be so much more readable with something like

Suggested change
.withTimeout(Duration.ofSeconds(timeout)) // GitLab starts in about 2 minutes
.withTimeout(Duration.ofSeconds(60 * 2)) // GitLab starts in about 2 minutes

or
suggestion
.withTimeout(Duration.ofMinutes(2)) // GitLab starts in about 2 minutes


Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

some incorect use of Elastic time with wait.

user.save!;

token = user.personal_access_tokens.create(scopes: [:api], name: 'MyToken');
token.expires_at='01/01/2024';
Copy link
Member

Choose a reason for hiding this comment

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

This will be problematic in 4 months.

this.assertExistAndResult(failureJob, false);

// delete the repo when finished
container.deleteRepo(getPrivateTokenAdmin(), repoName);
Copy link
Member

Choose a reason for hiding this comment

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

This should be done in a @After method or in a try { ... } finally {...} block because if any of the asserts above fails then the repo won't be deleted otherwise.


private String groupName = "firstgroup";

private String JenkinsfileContent = "pipeline {\n" +
Copy link
Member

Choose a reason for hiding this comment

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

This pipeline is using declarative syntax which should mean you need to declare the pipeline-model-definition plugin in the @WithPlugins annotation.

@raul-arabaolaza
Copy link
Contributor

Can we get this merged, please? No blockers apparently and the builder is happy

@rsandell rsandell changed the title Gitlab container Gitlab container and tests Sep 18, 2023
@rsandell rsandell merged commit 5e76540 into jenkinsci:master Sep 18, 2023
23 checks passed
@jtnord
Copy link
Member

jtnord commented Sep 18, 2023

@rsandell master is broken - looks like this PR is broken on java21?

@timja
Copy link
Member

timja commented Sep 20, 2023

Can this please be looked at quickly?

It's breaking all PRs.

@car-roll
Copy link
Contributor

This is from my first look at these failures: #1364 (comment)

@car-roll
Copy link
Contributor

Possible fix #1365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants