Skip to content

Commit

Permalink
Fix FSHealthServiceTests on Windows
Browse files Browse the repository at this point in the history
In elastic#52680 we introduced a new health check mechanism. This commit fixes
up some related test failures on Windows caused by erroneously assuming
that all paths begin with `/`.

Closes elastic#59380
  • Loading branch information
DaveCTurner committed Jul 13, 2020
1 parent f8002a7 commit e8f389f
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public void testSchedulesHealthCheckAtRefreshIntervals() throws Exception {
}

public void testFailsHealthOnIOException() throws IOException {
assumeFalse("https://github.com/elastic/elasticsearch/issues/59380", Constants.WINDOWS);

FileSystem fileSystem = PathUtils.getDefaultFileSystem();
FileSystemIOExceptionProvider disruptFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem);
fileSystem = disruptFileSystemProvider.getFileSystem(null);
Expand All @@ -116,6 +114,7 @@ public void testFailsHealthOnIOException() throws IOException {
assertEquals("health check passed", fsHealthService.getHealth().getInfo());

//disrupt file system
disruptFileSystemProvider.restrictPathPrefix(""); // disrupt all paths
disruptFileSystemProvider.injectIOException.set(true);
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
fsHealthService.new FsHealthMonitor().run();
Expand Down Expand Up @@ -221,9 +220,9 @@ public void testFailsHealthOnSinglePathWriteFailure() throws IOException {
assertEquals("health check passed", fsHealthService.getHealth().getInfo());

//disrupt file system writes on single path
disruptWritesFileSystemProvider.injectIOException.set(true);
String disruptedPath = randomFrom(paths).toString();
disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath);
disruptWritesFileSystemProvider.injectIOException.set(true);
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
fsHealthService.new FsHealthMonitor().run();
assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
Expand All @@ -241,7 +240,7 @@ private static class FileSystemIOExceptionProvider extends FilterFileSystemProvi
AtomicBoolean injectIOException = new AtomicBoolean();
AtomicInteger injectedPaths = new AtomicInteger();

private String pathPrefix = "/";
private String pathPrefix;

FileSystemIOExceptionProvider(FileSystem inner) {
super("disrupt_fs_health://", inner);
Expand All @@ -258,6 +257,7 @@ public int getInjectedPathCount(){
@Override
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException {
if (injectIOException.get()){
assert pathPrefix != null : "must set pathPrefix before starting disruptions";
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
injectedPaths.incrementAndGet();
throw new IOException("fake IOException");
Expand All @@ -272,7 +272,7 @@ private static class FileSystemFsyncIOExceptionProvider extends FilterFileSystem
AtomicBoolean injectIOException = new AtomicBoolean();
AtomicInteger injectedPaths = new AtomicInteger();

private String pathPrefix = "/";
private String pathPrefix = null;

FileSystemFsyncIOExceptionProvider(FileSystem inner) {
super("disrupt_fs_health://", inner);
Expand All @@ -292,6 +292,7 @@ public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options,
@Override
public void force(boolean metaData) throws IOException {
if (injectIOException.get()) {
assert pathPrefix != null : "must set pathPrefix before starting disruptions";
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
injectedPaths.incrementAndGet();
throw new IOException("fake IOException");
Expand Down

0 comments on commit e8f389f

Please sign in to comment.