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

Test Tor Installation and Startup Race Condition #1910

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading