Fix flaky test RestServerTest.testCORSEnabled
The test always fails if testOptionsDoesNotIncludeWadlOutput is executed before testCORSEnabled. It seems the problem is the use of the system property. Perhaps there is some static caching somewhere.
Reviewers: Randall Hauch Guozhang Wang
@@ -27,6 +27,7 @@ import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
@@ -58,6 +59,12 @@ public class RestServerTest {
private Plugins plugins;
private RestServer server;
+ @Before
+ public void setUp() {
+ // To be able to set the Origin, we need to toggle this flag
+ System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
+ }
+
@After
public void tearDown() {
server.stop();
@@ -185,13 +192,10 @@ public class RestServerTest {
}
public void checkCORSRequest(String corsDomain, String origin, String expectedHeader, String method) {
- // To be able to set the Origin, we need to toggle this flag
-
Map<String, String> workerProps = baseWorkerProps();
workerProps.put(WorkerConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG, corsDomain);
workerProps.put(WorkerConfig.ACCESS_CONTROL_ALLOW_METHODS_CONFIG, method);
WorkerConfig workerConfig = new DistributedConfig(workerProps);
- System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
EasyMock.expect(herder.plugins()).andStubReturn(plugins);
EasyMock.expect(plugins.newPlugins(Collections.emptyList(),
