Skip to content

Commit cb9acb2

Browse files
apuigjglicktimja
authored
Fix flaky GitLab await ready by using PageObject (and adapt to new Credentials) (jenkinsci#2608)
Co-authored-by: Jesse Glick <jglick@cloudbees.com> Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent cd7330d commit cb9acb2

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.jenkinsci.test.acceptance.docker.fixtures;
22

33
import java.io.IOException;
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
46
import java.time.Duration;
57
import org.jenkinsci.test.acceptance.docker.Docker;
68
import org.jenkinsci.test.acceptance.docker.DockerContainer;
79
import org.jenkinsci.test.acceptance.docker.DockerFixture;
810
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl;
11+
import org.openqa.selenium.WebDriverException;
912

1013
@DockerFixture(
1114
id = "gitlab-plugin",
@@ -53,15 +56,16 @@ public String extractProjectPath(String repoUrl) {
5356
return afterAuth.split("/", 2)[1].replace(".git", "");
5457
}
5558

56-
public void waitForReady(CapybaraPortingLayerImpl p) {
59+
public void waitForReady(CapybaraPortingLayerImpl p) throws MalformedURLException {
60+
GitLabPage gitLabPage = new GitLabPage(p.injector, new URL(getHttpUrl()));
5761
p.waitFor()
5862
.withMessage("Waiting for GitLab to come up")
5963
.withTimeout(READINESS_TIMEOUT)
6064
.pollingEvery(READINESS_POLL_INTERVAL)
65+
.ignoring(WebDriverException.class) // connection reset while not up
6166
.until(() -> {
62-
p.executeScript("window.location.href = arguments[0];", getHttpUrl());
63-
var page = p.getPageSource();
64-
return page != null && page.contains("GitLab Community Edition");
67+
gitLabPage.open();
68+
return gitLabPage.isReady();
6569
});
6670
}
6771

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.jenkinsci.test.acceptance.docker.fixtures;
2+
3+
import com.google.inject.Injector;
4+
import java.net.URL;
5+
import org.jenkinsci.test.acceptance.po.PageObject;
6+
7+
/** Wait for GitLab landing page */
8+
public class GitLabPage extends PageObject {
9+
public GitLabPage(Injector injector, URL url) {
10+
super(injector, url);
11+
}
12+
13+
public boolean isReady() {
14+
var page = getPageSource();
15+
return page != null && page.contains("GitLab Community Edition");
16+
}
17+
}

src/main/java/org/jenkinsci/test/acceptance/plugins/gitlab_plugin/GitLabPersonalAccessTokenCredential.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.jenkinsci.test.acceptance.plugins.gitlab_plugin;
22

3-
import static org.jenkinsci.test.acceptance.Matchers.hasContent;
4-
53
import org.jenkinsci.test.acceptance.plugins.credentials.BaseStandardCredentials;
64
import org.jenkinsci.test.acceptance.po.Control;
75
import org.jenkinsci.test.acceptance.po.Describable;
@@ -24,9 +22,4 @@ public GitLabPersonalAccessTokenCredential(PageAreaImpl area, String relativePat
2422
public void setToken(String gitLabToken) {
2523
token.set(gitLabToken);
2624
}
27-
28-
public void create() {
29-
control(by.path("/Submit")).click();
30-
waitFor(driver, hasContent("Global credentials"), 2);
31-
}
3225
}

src/test/java/plugins/GitLabPluginTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.junit.After;
5353
import org.junit.AfterClass;
5454
import org.junit.Before;
55-
import org.junit.Ignore;
5655
import org.junit.Test;
5756
import org.junit.experimental.categories.Category;
5857
import org.openqa.selenium.NoSuchElementException;
@@ -200,7 +199,6 @@ public static void tearDownGitLabContainer() {
200199
* Verifies multibranch pipeline discovers branches/MRs/tags, builds them, and detects dynamic branch
201200
*/
202201
@Test
203-
@Ignore("https://github.com/jenkinsci/acceptance-test-harness/issues/1461")
204202
public void testGitLabMultibranchPipeline() throws IOException {
205203
// Given a repository with 4 branches (3 valid, 1 broken) and 1 merge request
206204
Project project;
@@ -303,7 +301,6 @@ public void testGitLabMultibranchPipeline() throws IOException {
303301
* Verifies organization folder discovers group projects and indexes their branches/MRs.
304302
*/
305303
@Test
306-
@Ignore("https://github.com/jenkinsci/acceptance-test-harness/issues/1461")
307304
public void gitLabGroupFolderOrganization() throws IOException {
308305
// Given a GitLab group with 2 projects, each with 4 branches and 1 merge request
309306
try (var gitlabapi = new GitLabApi(CONTAINER.getHttpUrl(), ADMIN_TOKEN)
@@ -394,7 +391,7 @@ private void createGitLabToken(String token, String id) {
394391
var tk = cp.add(GitLabPersonalAccessTokenCredential.class);
395392
tk.setToken(token);
396393
tk.setId(id);
397-
tk.create();
394+
cp.create();
398395
}
399396

400397
private void configureGitLabServer() throws IOException {

0 commit comments

Comments
 (0)