Merge pull request #34467 from overleaf/dp-git-bridge-dynamic-port

[git-bridge] Bind integration test server to a dynamic port

GitOrigin-RevId: 12b570dbb4bc092c05e864c28ff554d672084804
This commit is contained in:
David
2026-06-11 08:05:14 +00:00
committed by Copybot
parent a36a6731b6
commit bfc46c4591
3 changed files with 178 additions and 176 deletions
@@ -65,6 +65,10 @@ public class GitBridgeApp implements Runnable {
server.stop();
}
public int getPort() {
return server.getPort();
}
/* Helper methods */
private void parseArguments(String[] args) throws ArgsException {
@@ -48,12 +48,16 @@ public class GitBridgeServer {
private final GceMetadataLogLevelChecker logLevelChecker;
private ServerConnector connector;
private final int port;
private final String bindIp;
private String rootGitDirectoryPath;
private String apiBaseURL;
public GitBridgeServer(Config config) throws ServletException {
this.port = config.getPort();
this.bindIp = config.getBindIp();
this.rootGitDirectoryPath = config.getRootGitDirectory();
RepoStore repoStore =
new FSGitRepoStore(
@@ -89,10 +93,18 @@ public class GitBridgeServer {
try {
bridge.checkDB();
jettyServer.start();
// Only the integration tests configure port 0, which lets the OS assign a free
// port at bind time. Production always configures an explicit non-zero port, so
// this branch never runs there.
if (port == 0) {
int actualPort = connector.getLocalPort();
String postbackURL = "http://" + bindIp + ":" + actualPort + "/";
Util.setPostbackURL(postbackURL);
}
bridge.startBackgroundJobs();
logLevelChecker.start();
Log.info(Util.getServiceName() + "-Git Bridge server started");
Log.info("Listening on port: " + port);
Log.info("Listening on port: " + getPort());
Log.info("Bridged to: " + apiBaseURL);
Log.info("Postback base URL: " + Util.getPostbackURL());
Log.info("Root git directory path: " + rootGitDirectoryPath);
@@ -103,6 +115,10 @@ public class GitBridgeServer {
}
}
public int getPort() {
return connector.getLocalPort();
}
public void stop() {
logLevelChecker.stop();
try {
@@ -114,7 +130,7 @@ public class GitBridgeServer {
private void configureJettyServer(Config config, RepoStore repoStore, SnapshotApi snapshotApi)
throws ServletException {
ServerConnector connector = new ServerConnector(this.jettyServer);
this.connector = new ServerConnector(this.jettyServer);
connector.setPort(config.getPort());
connector.setHost(config.getBindIp());
connector.setIdleTimeout(config.getIdleTimeout());