Revision: 8798
Author: [email protected]
Date: Thu Sep 16 08:28:57 2010
Log: Calling the reset methods from gwtTearDown() results in nondeterminism.
Patch by: bobv
Review by: rjrjr
Review at http://gwt-code-reviews.appspot.com/890801
http://code.google.com/p/google-web-toolkit/source/detail?r=8798
Added:
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTestBase.java
Modified:
/trunk/user/test/com/google/gwt/requestfactory/client/EditorTest.java
/trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTestBase.java
Thu Sep 16 08:28:57 2010
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.requestfactory.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.shared.EventBus;
+import com.google.gwt.event.shared.SimpleEventBus;
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.requestfactory.shared.Receiver;
+import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
+import com.google.gwt.requestfactory.shared.SyncResult;
+
+import java.util.Set;
+
+/**
+ * A base class for anything that makes use of the SimpleRequestFactory.
+ * Subclasses must always use {...@link #finishTestAndReset()} in order to
allow
+ * calls to the reset methods to complete before the next test starts.
+ *
+ */
+public abstract class RequestFactoryTestBase extends GWTTestCase {
+
+ protected SimpleRequestFactory req;
+ protected EventBus eventBus;
+
+ @Override
+ public void gwtSetUp() {
+ eventBus = new SimpleEventBus();
+ req = GWT.create(SimpleRequestFactory.class);
+ req.init(eventBus);
+ }
+
+ protected void finishTestAndReset() {
+ final boolean[] reallyDone = {false, false};
+ req.simpleFooRequest().reset().fire(new Receiver<Void>() {
+ public void onSuccess(Void response, Set<SyncResult> syncResults) {
+ reallyDone[0] = true;
+ if (reallyDone[0] && reallyDone[1]) {
+ finishTest();
+ }
+ }
+ });
+ req.simpleBarRequest().reset().fire(new Receiver<Void>() {
+ public void onSuccess(Void response, Set<SyncResult> syncResults) {
+ reallyDone[1] = true;
+ if (reallyDone[0] && reallyDone[1]) {
+ finishTest();
+ }
+ }
+ });
+ }
+}
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/EditorTest.java
Wed Sep 15 06:48:28 2010
+++ /trunk/user/test/com/google/gwt/requestfactory/client/EditorTest.java
Thu Sep 16 08:28:57 2010
@@ -24,14 +24,10 @@
import com.google.gwt.editor.client.HasEditorDelegate;
import com.google.gwt.editor.client.HasEditorErrors;
import com.google.gwt.editor.client.adapters.SimpleEditor;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.SimpleEventBus;
-import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.requestfactory.shared.ProxyRequest;
import com.google.gwt.requestfactory.shared.Receiver;
import com.google.gwt.requestfactory.shared.SimpleBarProxy;
import com.google.gwt.requestfactory.shared.SimpleFooProxy;
-import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
import com.google.gwt.requestfactory.shared.SyncResult;
import com.google.gwt.requestfactory.shared.Violation;
@@ -44,7 +40,11 @@
* RequestFactory-specific features belong here; all other tests should
use the
* SimpleBeanEditorDriver to make the tests simpler.
*/
-public class EditorTest extends GWTTestCase {
+public class EditorTest extends RequestFactoryTestBase {
+ /*
+ * DO NOT USE finishTest(). Instead, call finishTestAndReset();
+ */
+
static class SimpleBarEditor implements Editor<SimpleBarProxy> {
protected final SimpleEditor<String> userName = SimpleEditor.of();
}
@@ -90,9 +90,6 @@
this.delegate = delegate;
}
}
-
- private EventBus eventBus;
- private SimpleRequestFactory factory;
private static final int TEST_TIMEOUT = 5000;
@@ -100,40 +97,20 @@
public String getModuleName() {
return "com.google.gwt.requestfactory.RequestFactorySuite";
}
-
- @Override
- public void gwtSetUp() {
- factory = GWT.create(SimpleRequestFactory.class);
- eventBus = new SimpleEventBus();
- factory.init(eventBus);
- }
-
- @Override
- public void gwtTearDown() {
- factory.simpleFooRequest().reset().fire(new Receiver<Void>() {
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- factory.simpleBarRequest().reset().fire(new Receiver<Void>() {
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- }
public void test() {
delayTestFinish(TEST_TIMEOUT);
final SimpleFooEditor editor = new SimpleFooEditor();
final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
- driver.initialize(eventBus, factory, editor);
-
-
factory.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
+ driver.initialize(eventBus, req, editor);
+
+
req.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
new Receiver<SimpleFooProxy>() {
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResults) {
- driver.edit(response,
-
factory.simpleFooRequest().persistAndReturnSelf(response).with(
- driver.getPaths()));
+ driver.edit(response,
req.simpleFooRequest().persistAndReturnSelf(
+ response).with(driver.getPaths()));
assertEquals("GWT", editor.userName.getValue());
assertEquals("FOO", editor.barEditor().userName.getValue());
@@ -149,7 +126,7 @@
assertEquals("EditorFooTest", response.getUserName());
assertEquals("EditorBarTest",
response.getBarField().getUserName());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -161,12 +138,12 @@
final SimpleFooEditorWithDelegate editor = new
SimpleFooEditorWithDelegate();
final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
- driver.initialize(eventBus, factory, editor);
+ driver.initialize(eventBus, req, editor);
assertEquals(Arrays.asList("barField.userName", "barField"),
Arrays.asList(driver.getPaths()));
-
factory.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
+
req.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
new Receiver<SimpleFooProxy>() {
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResults) {
@@ -175,9 +152,9 @@
assertNotNull(editor.delegate.subscribe());
// Simulate edits occurring elsewhere in the module
- ProxyRequest<SimpleFooProxy> request =
factory.simpleFooRequest().persistAndReturnSelf(
+ ProxyRequest<SimpleFooProxy> request =
req.simpleFooRequest().persistAndReturnSelf(
response);
- SimpleBarProxy newBar = factory.create(SimpleBarProxy.class);
+ SimpleBarProxy newBar = req.create(SimpleBarProxy.class);
newBar = request.edit(newBar);
newBar.setUserName("newBar");
response = request.edit(response);
@@ -193,7 +170,7 @@
assertEquals("updated", editor.userName.getValue());
assertEquals("newBar",
editor.barEditor().userName.getValue());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -207,15 +184,14 @@
final SimpleFooEditor editor = new SimpleFooEditor();
final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
- driver.initialize(eventBus, factory, editor);
-
-
factory.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
+ driver.initialize(eventBus, req, editor);
+
+
req.simpleFooRequest().findSimpleFooById(0L).with(driver.getPaths()).fire(
new Receiver<SimpleFooProxy>() {
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResults) {
- driver.edit(response,
-
factory.simpleFooRequest().persistAndReturnSelf(response).with(
- driver.getPaths()));
+ driver.edit(response,
req.simpleFooRequest().persistAndReturnSelf(
+ response).with(driver.getPaths()));
// Set to an illegal value
editor.userName.setValue("");
@@ -241,10 +217,11 @@
assertEquals("userName", error.getPath());
assertSame(v, error.getUserData());
assertNull(error.getValue());
- finishTest();
+ finishTestAndReset();
}
});
}
});
}
-}
+
+}
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java
Wed Sep 15 03:48:29 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java
Thu Sep 16 08:28:57 2010
@@ -15,14 +15,10 @@
*/
package com.google.gwt.requestfactory.client;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
-import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.requestfactory.shared.EntityProxy;
import com.google.gwt.requestfactory.shared.EntityProxyId;
import com.google.gwt.requestfactory.shared.Receiver;
import com.google.gwt.requestfactory.shared.SimpleFooProxy;
-import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
import com.google.gwt.requestfactory.shared.SyncResult;
import java.util.Set;
@@ -30,34 +26,15 @@
/**
* Tests for {...@link com.google.gwt.requestfactory.shared.RequestFactory}.
*/
-public class FindServiceTest extends GWTTestCase {
-
- private SimpleRequestFactory req;
+public class FindServiceTest extends RequestFactoryTestBase {
+ /*
+ * DO NOT USE finishTest(). Instead, call finishTestAndReset();
+ */
@Override
public String getModuleName() {
return "com.google.gwt.requestfactory.RequestFactorySuite";
}
-
- @Override
- public void gwtSetUp() {
- req = GWT.create(SimpleRequestFactory.class);
- req.init(new SimpleEventBus());
- }
-
- @Override
- public void gwtTearDown() {
- req.simpleFooRequest().reset().fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- req.simpleBarRequest().reset().fire(new Receiver<Void>() {
- @Override
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- }
public void testFetchEntity() {
final boolean relationsAbsent = false;
@@ -68,23 +45,23 @@
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResult) {
checkReturnedProxy(response, relationsAbsent);
-
+
final EntityProxyId stableId = response.stableId();
- req.find(stableId).fire(
- new Receiver<EntityProxy>() {
-
- @Override
- public void onSuccess(EntityProxy returnedProxy,
- Set<SyncResult> syncResults) {
- assertEquals(stableId, returnedProxy.stableId());
- checkReturnedProxy((SimpleFooProxy) returnedProxy,
relationsAbsent);
- finishTest();
- }
- });
+ req.find(stableId).fire(new Receiver<EntityProxy>() {
+
+ @Override
+ public void onSuccess(EntityProxy returnedProxy,
+ Set<SyncResult> syncResults) {
+ assertEquals(stableId, returnedProxy.stableId());
+ checkReturnedProxy((SimpleFooProxy) returnedProxy,
+ relationsAbsent);
+ finishTestAndReset();
+ }
+ });
}
});
}
-
+
public void testFetchEntityWithRelation() {
final boolean relationsPresent = true;
delayTestFinish(5000);
@@ -94,7 +71,7 @@
public void onSuccess(SimpleFooProxy response,
Set<SyncResult> syncResult) {
checkReturnedProxy(response, relationsPresent);
-
+
final EntityProxyId stableId = response.stableId();
req.find(stableId).with("barField").fire(
new Receiver<EntityProxy>() {
@@ -103,15 +80,17 @@
public void onSuccess(EntityProxy returnedProxy,
Set<SyncResult> syncResults) {
assertEquals(stableId, returnedProxy.stableId());
- checkReturnedProxy((SimpleFooProxy) returnedProxy,
relationsPresent);
- finishTest();
+ checkReturnedProxy((SimpleFooProxy) returnedProxy,
+ relationsPresent);
+ finishTestAndReset();
}
});
}
});
}
- private void checkReturnedProxy(SimpleFooProxy response, boolean
checkForRelations) {
+ private void checkReturnedProxy(SimpleFooProxy response,
+ boolean checkForRelations) {
assertEquals(42, (int) response.getIntId());
assertEquals("GWT", response.getUserName());
assertEquals(8L, (long) response.getLongField());
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Tue Sep 14 03:12:23 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Thu Sep 16 08:28:57 2010
@@ -15,9 +15,6 @@
*/
package com.google.gwt.requestfactory.client;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
-import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.requestfactory.client.impl.ProxyImpl;
import com.google.gwt.requestfactory.shared.EntityProxy;
import com.google.gwt.requestfactory.shared.EntityProxyId;
@@ -25,7 +22,6 @@
import com.google.gwt.requestfactory.shared.RequestObject;
import com.google.gwt.requestfactory.shared.SimpleBarProxy;
import com.google.gwt.requestfactory.shared.SimpleFooProxy;
-import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
import com.google.gwt.requestfactory.shared.SyncResult;
import com.google.gwt.requestfactory.shared.Violation;
@@ -34,7 +30,10 @@
/**
* Tests for {...@link com.google.gwt.requestfactory.shared.RequestFactory}.
*/
-public class RequestFactoryTest extends GWTTestCase {
+public class RequestFactoryTest extends RequestFactoryTestBase {
+ /*
+ * DO NOT USE finishTest(). Instead, call finishTestAndReset();
+ */
private class ShouldNotSuccedReceiver<T> extends Receiver<T> {
@@ -66,34 +65,14 @@
assertEquals("size must be between 3 and 30", error.getMessage());
assertEquals("Did not receive expeceted id", expectedId,
error.getProxyId());
- finishTest();
+ finishTestAndReset();
}
}
-
- private SimpleRequestFactory req;
@Override
public String getModuleName() {
return "com.google.gwt.requestfactory.RequestFactorySuite";
}
-
- @Override
- public void gwtSetUp() {
- req = GWT.create(SimpleRequestFactory.class);
- req.init(new SimpleEventBus());
- }
-
- @Override
- public void gwtTearDown() {
- req.simpleFooRequest().reset().fire(new Receiver<Void>() {
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- req.simpleBarRequest().reset().fire(new Receiver<Void>() {
- public void onSuccess(Void response, Set<SyncResult> syncResults) {
- }
- });
- }
public void testDummyCreate() {
delayTestFinish(5000);
@@ -113,7 +92,7 @@
assertTrue(((ProxyImpl) foo).isFuture());
checkStableIdEquals(foo, returned);
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -130,7 +109,7 @@
assertEquals(com.google.gwt.requestfactory.shared.SimpleEnum.FOO,
response.getEnumField());
assertEquals(null, response.getBarField());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -147,7 +126,7 @@
assertEquals(com.google.gwt.requestfactory.shared.SimpleEnum.FOO,
response.getEnumField());
assertNotNull(response.getBarField());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -184,7 +163,7 @@
public void onSuccess(SimpleFooProxy finalFoo,
Set<SyncResult> syncResults) {
assertEquals("Ray", finalFoo.getUserName());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -215,7 +194,7 @@
updReq.fire(new Receiver<Void>() {
public void onSuccess(Void response,
Set<SyncResult> syncResults) {
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -254,7 +233,7 @@
// barReq hasn't been persisted, so old value
assertEquals("FOO",
finalFooProxy.getBarField().getUserName());
- finishTest();
+ finishTestAndReset();
}
});
@@ -292,9 +271,8 @@
// newFoo hasn't been persisted, so userName is
the old
// value.
assertEquals("GWT", finalFooProxy.getUserName());
- finishTest();
- }
-
+ finishTestAndReset();
+ }
});
}
});
@@ -341,9 +319,8 @@
Set<SyncResult> syncResults) {
assertEquals("Amit",
finalFooProxy.getBarField().getUserName());
- finishTest();
- }
-
+ finishTestAndReset();
+ }
});
}
});
@@ -365,7 +342,7 @@
persistRay.fire(new Receiver<SimpleFooProxy>() {
public void onSuccess(final SimpleFooProxy persistedRay,
Set<SyncResult> ignored) {
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -402,7 +379,7 @@
public void onSuccess(SimpleFooProxy relatedRay,
Set<SyncResult> ignored) {
assertEquals("Amit",
relatedRay.getBarField().getUserName());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -425,7 +402,7 @@
helloReq.fire(new Receiver<String>() {
public void onSuccess(String response, Set<SyncResult>
syncResults) {
assertEquals("Greetings BAR from GWT", response);
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -472,7 +449,7 @@
Set<SyncResult> syncResults) {
checkStableIdEquals(editableFoo, returnedAfterEdit);
assertEquals(returnedAfterEdit.getId(), returned.getId());
- finishTest();
+ finishTestAndReset();
}
});
}
@@ -491,7 +468,7 @@
fooReq.fire(new Receiver<Void>() {
public void onSuccess(Void ignore, Set<SyncResult> syncResults) {
assertEquals(1, syncResults.size());
- finishTest();
+ finishTestAndReset();
}
});
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors