Skip to content

Commit e63f2f8

Browse files
authored
Fix FSHealthServiceTests on Windows (#59387)
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
1 parent 3cb9105 commit e63f2f8

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
* under the License.
1818
*/
1919

20-
2120
package org.elasticsearch.monitor.fs;
2221

23-
2422
import org.apache.logging.log4j.Level;
2523
import org.apache.logging.log4j.LogManager;
2624
import org.apache.logging.log4j.Logger;
2725
import org.apache.lucene.mockfile.FilterFileChannel;
2826
import org.apache.lucene.mockfile.FilterFileSystemProvider;
29-
import org.apache.lucene.util.Constants;
3027
import org.elasticsearch.cluster.coordination.DeterministicTaskQueue;
3128
import org.elasticsearch.common.io.PathUtils;
3229
import org.elasticsearch.common.io.PathUtilsForTesting;
@@ -58,7 +55,6 @@
5855
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
5956
import static org.hamcrest.Matchers.is;
6057

61-
6258
public class FsHealthServiceTests extends ESTestCase {
6359

6460
private DeterministicTaskQueue deterministicTaskQueue;
@@ -100,8 +96,6 @@ public void testSchedulesHealthCheckAtRefreshIntervals() throws Exception {
10096
}
10197

10298
public void testFailsHealthOnIOException() throws IOException {
103-
assumeFalse("https://github.com/elastic/elasticsearch/issues/59380", Constants.WINDOWS);
104-
10599
FileSystem fileSystem = PathUtils.getDefaultFileSystem();
106100
FileSystemIOExceptionProvider disruptFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem);
107101
fileSystem = disruptFileSystemProvider.getFileSystem(null);
@@ -116,6 +110,7 @@ public void testFailsHealthOnIOException() throws IOException {
116110
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
117111

118112
//disrupt file system
113+
disruptFileSystemProvider.restrictPathPrefix(""); // disrupt all paths
119114
disruptFileSystemProvider.injectIOException.set(true);
120115
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
121116
fsHealthService.new FsHealthMonitor().run();
@@ -221,9 +216,9 @@ public void testFailsHealthOnSinglePathWriteFailure() throws IOException {
221216
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
222217

223218
//disrupt file system writes on single path
224-
disruptWritesFileSystemProvider.injectIOException.set(true);
225219
String disruptedPath = randomFrom(paths).toString();
226220
disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath);
221+
disruptWritesFileSystemProvider.injectIOException.set(true);
227222
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
228223
fsHealthService.new FsHealthMonitor().run();
229224
assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
@@ -241,7 +236,7 @@ private static class FileSystemIOExceptionProvider extends FilterFileSystemProvi
241236
AtomicBoolean injectIOException = new AtomicBoolean();
242237
AtomicInteger injectedPaths = new AtomicInteger();
243238

244-
private String pathPrefix = "/";
239+
private String pathPrefix;
245240

246241
FileSystemIOExceptionProvider(FileSystem inner) {
247242
super("disrupt_fs_health://", inner);
@@ -258,6 +253,7 @@ public int getInjectedPathCount(){
258253
@Override
259254
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException {
260255
if (injectIOException.get()){
256+
assert pathPrefix != null : "must set pathPrefix before starting disruptions";
261257
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
262258
injectedPaths.incrementAndGet();
263259
throw new IOException("fake IOException");
@@ -272,7 +268,7 @@ private static class FileSystemFsyncIOExceptionProvider extends FilterFileSystem
272268
AtomicBoolean injectIOException = new AtomicBoolean();
273269
AtomicInteger injectedPaths = new AtomicInteger();
274270

275-
private String pathPrefix = "/";
271+
private String pathPrefix = null;
276272

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

0 commit comments

Comments
 (0)