mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
Fix flaky tests with TaskQueueExtension (#1909)
The temporary queue.xml file is not deleted in the afterEach() method, likely causing some flaky tests that we saw due to overwriting of the file by concurrent tests.
This commit is contained in:
parent
4067f7c3e4
commit
f65b6ece5d
1 changed files with 7 additions and 10 deletions
|
@ -22,7 +22,8 @@ import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
|
||||||
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig;
|
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig;
|
||||||
import com.google.apphosting.api.ApiProxy;
|
import com.google.apphosting.api.ApiProxy;
|
||||||
import google.registry.model.annotations.DeleteAfterMigration;
|
import google.registry.model.annotations.DeleteAfterMigration;
|
||||||
import java.io.File;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
@ -39,26 +40,22 @@ public final class TaskQueueExtension implements BeforeEachCallback, AfterEachCa
|
||||||
readResourceUtf8("google/registry/env/common/default/WEB-INF/queue.xml");
|
readResourceUtf8("google/registry/env/common/default/WEB-INF/queue.xml");
|
||||||
|
|
||||||
private LocalServiceTestHelper helper;
|
private LocalServiceTestHelper helper;
|
||||||
private String taskQueueXml;
|
private Path queueFile;
|
||||||
private File tmpDir;
|
|
||||||
|
|
||||||
public TaskQueueExtension() {
|
|
||||||
this.taskQueueXml = QUEUE_XML;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeEach(ExtensionContext context) throws Exception {
|
public void beforeEach(ExtensionContext context) throws Exception {
|
||||||
File queueFile = new File(tmpDir, "queue.xml");
|
queueFile = Files.createTempFile("queue", ".xml");
|
||||||
asCharSink(queueFile, UTF_8).write(taskQueueXml);
|
asCharSink(queueFile.toFile(), UTF_8).write(QUEUE_XML);
|
||||||
helper =
|
helper =
|
||||||
new LocalServiceTestHelper(
|
new LocalServiceTestHelper(
|
||||||
new LocalTaskQueueTestConfig().setQueueXmlPath(queueFile.getAbsolutePath()));
|
new LocalTaskQueueTestConfig().setQueueXmlPath(queueFile.toAbsolutePath().toString()));
|
||||||
helper.setUp();
|
helper.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(ExtensionContext context) throws Exception {
|
public void afterEach(ExtensionContext context) throws Exception {
|
||||||
helper.tearDown();
|
helper.tearDown();
|
||||||
|
Files.delete(queueFile);
|
||||||
ApiProxy.setEnvironmentForCurrentThread(null);
|
ApiProxy.setEnvironmentForCurrentThread(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue