@@ -789,99 +789,50 @@ public void run() {
789
789
}
790
790
791
791
/**
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.
799
794
*/
800
795
@ Test
801
796
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
-
812
797
final ComponentContext c = mLegacyLithoViewRule .context ;
813
-
814
798
final RenderAndMeasureCounter counter = new RenderAndMeasureCounter ();
815
799
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 );
836
802
837
803
final Component component =
838
804
Column .create (c )
839
- .child (
840
- RenderAndLayoutCountingTester .create (c )
841
- .renderAndMeasureCounter (counter )
842
- .listener (listener ))
805
+ .child (RenderAndLayoutCountingTester .create (c ).renderAndMeasureCounter (counter ))
843
806
.build ();
844
807
845
- final int widthSpec = SizeSpec .makeSizeSpec (100 , SizeSpec .EXACTLY );
846
- final int heightSpec = SizeSpec .makeSizeSpec (100 , SizeSpec .EXACTLY );
847
-
848
808
final ComponentTree componentTree = mLegacyLithoViewRule .getComponentTree ();
849
809
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 ();
862
812
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 ) );
865
815
866
816
componentTree .setFutureExecutionListener (
867
817
type -> {
868
818
componentTree .setFutureExecutionListener (null );
869
819
870
- // Inform 2nd future's pre-execution occurred.
871
- waitForSecondPreFutureExecutionLatch . release ();
820
+ // unblock the async resolve
821
+ onPrepareLatch . acquire ();
872
822
});
873
823
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 );
879
826
880
827
// Ensure render and measure only happened once
881
828
assertThat (counter .getRenderCount ()).isEqualTo (1 );
882
829
assertThat (mLithoStatsRule .getResolveCount ()).isEqualTo (1 );
883
830
assertThat (counter .getMeasureCount ()).isEqualTo (1 );
884
831
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 );
885
836
}
886
837
887
838
/**
0 commit comments