Skip to content

Commit 8ddac31

Browse files
adityasharatfacebook-github-bot
authored andcommitted
Put back the Testing Configuration in the LithoTestRunner
Summary: By accident I had removed the testing configurations in our `LithoTestRunner`. I am putting them back as they should be. Reviewed By: astreet Differential Revision: D43386326 fbshipit-source-id: d0a1a384bc3dc9eab1c609889fbce596139fcd76
1 parent 8b0edfb commit 8ddac31

File tree

2 files changed

+18
-67
lines changed

2 files changed

+18
-67
lines changed

litho-it/src/test/java/com/facebook/litho/SplitFuturesTest.java

+17-66
Original file line numberDiff line numberDiff line change
@@ -789,99 +789,50 @@ public void run() {
789789
}
790790

791791
/**
792-
* When an async setRootAndSizeSpec happens, followed by an equivalent sync call, we expect the
793-
* async process to be promoted to the main thread, thus ensuring render and measure only happen
794-
* once.
795-
*
796-
* <p>The test verifies this behaviour works correctly during render by triggering an async
797-
* setRootAndSizeSpec, waiting for render to begin, and then triggering an equivalent sync
798-
* process.
792+
* When an async setRootAndSizeSpec happens, followed by a main thread layout, the async tasks
793+
* should be promoted to the main thread, thus ensuring resolve and measure only happen once.
799794
*/
800795
@Test
801796
public void testSyncRenderContinuesAsyncOnMainThread() {
802-
// Only relevant when futures are split
803-
if (!ComponentsConfiguration.isResolveAndLayoutFuturesSplitEnabled) {
804-
return;
805-
}
806-
807-
// This isn't written to run without early interruption
808-
if (!ComponentsConfiguration.isInterruptEarlyWithSplitFuturesEnabled) {
809-
return;
810-
}
811-
812797
final ComponentContext c = mLegacyLithoViewRule.context;
813-
814798
final RenderAndMeasureCounter counter = new RenderAndMeasureCounter();
815799

816-
// Latch to wait for async render to begin before sync render
817-
final TimeOutSemaphore waitForAsyncRenderToStartLatch = new TimeOutSemaphore(0);
818-
819-
// Latch to wait for the 2nd future's pre-execution
820-
final TimeOutSemaphore waitForSecondPreFutureExecutionLatch = new TimeOutSemaphore(0);
821-
822-
final RenderAndLayoutCountingTesterSpec.Listener listener =
823-
new RenderAndLayoutCountingTesterSpec.Listener() {
824-
@Override
825-
public void onPrepare() {
826-
// Inform async render has started
827-
waitForAsyncRenderToStartLatch.release();
828-
829-
// Wait for the 2nd future's pre-execution
830-
waitForSecondPreFutureExecutionLatch.acquire();
831-
}
832-
833-
@Override
834-
public void onMeasure() {}
835-
};
800+
// latch to wait for the main thread layout
801+
final TimeOutSemaphore onPrepareLatch = new TimeOutSemaphore(0);
836802

837803
final Component component =
838804
Column.create(c)
839-
.child(
840-
RenderAndLayoutCountingTester.create(c)
841-
.renderAndMeasureCounter(counter)
842-
.listener(listener))
805+
.child(RenderAndLayoutCountingTester.create(c).renderAndMeasureCounter(counter))
843806
.build();
844807

845-
final int widthSpec = SizeSpec.makeSizeSpec(100, SizeSpec.EXACTLY);
846-
final int heightSpec = SizeSpec.makeSizeSpec(100, SizeSpec.EXACTLY);
847-
848808
final ComponentTree componentTree = mLegacyLithoViewRule.getComponentTree();
849809

850-
// Set root and size-spec async
851-
componentTree.setRootAndSizeSpecAsync(component, widthSpec, heightSpec);
852-
853-
// run to end of tasks on background to avoid blocking here
854-
final TimeOutSemaphore bgThreadLatch =
855-
runOnBackgroundThread(
856-
new Runnable() {
857-
@Override
858-
public void run() {
859-
mLegacyLithoViewRule.runToEndOfBackgroundTasks();
860-
}
861-
});
810+
// wait in prepare
811+
onPrepareLatch.release();
862812

863-
// Wait for async render to start
864-
waitForAsyncRenderToStartLatch.acquire();
813+
// set root and size-spec async
814+
componentTree.setRootAndSizeSpecAsync(component, exactly(100), exactly(100));
865815

866816
componentTree.setFutureExecutionListener(
867817
type -> {
868818
componentTree.setFutureExecutionListener(null);
869819

870-
// Inform 2nd future's pre-execution occurred.
871-
waitForSecondPreFutureExecutionLatch.release();
820+
// unblock the async resolve
821+
onPrepareLatch.acquire();
872822
});
873823

874-
// Set root and sync-spec sync
875-
componentTree.setRootAndSizeSpecSync(component, widthSpec, heightSpec);
876-
877-
// Let the bg thread finish
878-
bgThreadLatch.acquire();
824+
// request a main thread layout
825+
componentTree.measure(exactly(200), exactly(200), new int[] {0, 0}, false);
879826

880827
// Ensure render and measure only happened once
881828
assertThat(counter.getRenderCount()).isEqualTo(1);
882829
assertThat(mLithoStatsRule.getResolveCount()).isEqualTo(1);
883830
assertThat(counter.getMeasureCount()).isEqualTo(1);
884831
assertThat(mLithoStatsRule.getLayoutCount()).isEqualTo(1);
832+
833+
// verify that the layout is measured against the new size
834+
assertThat(mLegacyLithoViewRule.getCommittedLayoutState().getWidth()).isEqualTo(200);
835+
assertThat(mLegacyLithoViewRule.getCommittedLayoutState().getHeight()).isEqualTo(200);
885836
}
886837

887838
/**

litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LithoTestRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public LithoTestRunner(final Class<?> testClass) throws InitializationError {
7171
* configurations.
7272
*/
7373
private List<? extends Class<? extends LithoTestRunConfiguration>> getGlobalConfigs() {
74-
return Arrays.asList();
74+
return Arrays.asList(SplitBuildAndLayoutTestRunConfiguration.class);
7575
}
7676

7777
@Override

0 commit comments

Comments
 (0)