From e8f389f10c5849858be6e724aa887a37bfad5f27 Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 13 Jul 2020 10:24:04 +0100 Subject: [PATCH] Fix FSHealthServiceTests on Windows In #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 #59380 --- .../monitor/fs/FsHealthServiceTests.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java b/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java index 14bda6f4f445c..9c478f2492b50 100644 --- a/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java +++ b/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java @@ -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); @@ -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(); @@ -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()); @@ -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); @@ -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"); @@ -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); @@ -292,6 +292,7 @@ public FileChannel newFileChannel(Path path, Set 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");