Skip to content

Commit

Permalink
Merge pull request #1910 from alvasw/test_tor_installation_startup_ra…
Browse files Browse the repository at this point in the history
…ce_condition

Test Tor Installation and Startup Race Condition
  • Loading branch information
alvasw authored Mar 23, 2024
2 parents 8aa1255 + 930995a commit aa6481a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("bisq.java-conventions")
id("bisq.java-integration-tests")
id("bisq.protobuf")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor;

import bisq.tor.installer.TorInstallationFiles;
import bisq.tor.installer.TorInstaller;
import bisq.tor.process.LdPreload;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

public class InstallerAndRunRaceConditionTest {
@Test
void test(@TempDir Path tempDir) throws IOException, InterruptedException {
var torInstallationFiles = new TorInstallationFiles(tempDir);
var torInstaller = new TorInstaller(torInstallationFiles);
torInstaller.installIfNotUpToDate();

Path torBinaryPath = tempDir.resolve("tor");
var processBuilder = new ProcessBuilder(
torBinaryPath.toAbsolutePath().toString(),
"--version"
);

Map<String, String> environment = processBuilder.environment();
environment.put("LD_PRELOAD", LdPreload.computeLdPreloadVariable(tempDir));

Process process = processBuilder.start();
boolean isSuccess = process.waitFor(30, TimeUnit.SECONDS);

assertThat(isSuccess).isTrue();
assertThat(process.exitValue()).isEqualTo(0);
}
}

0 comments on commit aa6481a

Please sign in to comment.