mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
Right now when an image node enters preload state, we kick off an image request with the default priority. Then when it enters display state, we change the priority to "imminent" which is mapped to the default priority as well. This means that requests from preload and display nodes have the same priority and are put to the same pool. The right behavior would be that preload requests should have a lower priority from the beginning. Another problem is that, due to the execution order of -didEnter(Preload|Display|Visible)State calls, a node may kick off a low priority request when it enters preload state even though it knows that it's also visible. By the time -didEnterVisibleState is called, the low priority request may have already been consumed and the download/data task won't pick up the new higher priority, or some work needs to be done to move it to another queue. A better behavior would be to always use the current interface state to determine the priority. This means that visible nodes will kick off high priority requests as soon as -didEnterPreloadState is called. The last (and smaller) issue is that a node marks its request as preload/low priority as soon as it exits visible state. I'd argue that this is too agressive. It may be reasonble for nodes in the trailing direction. Even so, we already handle this case by (almost always) have smaller trailing buffers. So this diff makes sure that nodes that exited visible state will have imminent/default priority if they remain in the display range. All of these new behaviors are wrapped in an experiment and will be tested carefully before being rolled out. * Add imports * Fix build failure * Encapsulate common logics into methods * Address comments
142 lines
4.1 KiB
Plaintext
142 lines
4.1 KiB
Plaintext
//
|
|
// ASConfigurationTests.m
|
|
// Texture
|
|
//
|
|
// Copyright (c) Pinterest, Inc. All rights reserved.
|
|
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import <AsyncDisplayKit/ASAvailability.h>
|
|
#import <AsyncDisplayKit/ASConfiguration.h>
|
|
#import <AsyncDisplayKit/ASConfigurationDelegate.h>
|
|
#import <AsyncDisplayKit/ASConfigurationInternal.h>
|
|
|
|
#import "ASTestCase.h"
|
|
|
|
static ASExperimentalFeatures features[] = {
|
|
ASExperimentalGraphicsContexts,
|
|
#if AS_ENABLE_TEXTNODE
|
|
ASExperimentalTextNode,
|
|
#endif
|
|
ASExperimentalInterfaceStateCoalescing,
|
|
ASExperimentalUnfairLock,
|
|
ASExperimentalLayerDefaults,
|
|
ASExperimentalCollectionTeardown,
|
|
ASExperimentalFramesetterCache,
|
|
ASExperimentalSkipClearData,
|
|
ASExperimentalDidEnterPreloadSkipASMLayout,
|
|
ASExperimentalDisableAccessibilityCache,
|
|
ASExperimentalSkipAccessibilityWait,
|
|
ASExperimentalNewDefaultCellLayoutMode,
|
|
ASExperimentalDispatchApply,
|
|
ASExperimentalImageDownloaderPriority
|
|
};
|
|
|
|
@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
|
|
|
|
@end
|
|
|
|
@implementation ASConfigurationTests {
|
|
void (^onActivate)(ASConfigurationTests *self, ASExperimentalFeatures feature);
|
|
}
|
|
|
|
+ (NSArray *)names {
|
|
return @[
|
|
@"exp_graphics_contexts",
|
|
@"exp_text_node",
|
|
@"exp_interface_state_coalesce",
|
|
@"exp_unfair_lock",
|
|
@"exp_infer_layer_defaults",
|
|
@"exp_collection_teardown",
|
|
@"exp_framesetter_cache",
|
|
@"exp_skip_clear_data",
|
|
@"exp_did_enter_preload_skip_asm_layout",
|
|
@"exp_disable_a11y_cache",
|
|
@"exp_skip_a11y_wait",
|
|
@"exp_new_default_cell_layout_mode",
|
|
@"exp_dispatch_apply",
|
|
@"exp_image_downloader_priority"
|
|
];
|
|
}
|
|
|
|
- (ASExperimentalFeatures)allFeatures {
|
|
ASExperimentalFeatures allFeatures = 0;
|
|
for (int i = 0; i < sizeof(features)/sizeof(ASExperimentalFeatures); i++) {
|
|
allFeatures |= features[i];
|
|
}
|
|
return allFeatures;
|
|
}
|
|
|
|
#if AS_ENABLE_TEXTNODE
|
|
|
|
- (void)testExperimentalFeatureConfig
|
|
{
|
|
// Set the config
|
|
ASConfiguration *config = [[ASConfiguration alloc] initWithDictionary:nil];
|
|
config.experimentalFeatures = ASExperimentalGraphicsContexts;
|
|
config.delegate = self;
|
|
[ASConfigurationManager test_resetWithConfiguration:config];
|
|
|
|
// Set an expectation for a callback, and assert we only get one.
|
|
XCTestExpectation *e = [self expectationWithDescription:@"Callbacks done."];
|
|
e.expectedFulfillmentCount = 2;
|
|
e.assertForOverFulfill = YES;
|
|
onActivate = ^(ASConfigurationTests *self, ASExperimentalFeatures feature) {
|
|
[e fulfill];
|
|
};
|
|
|
|
// Now activate the graphics experiment and expect it works.
|
|
XCTAssertTrue(ASActivateExperimentalFeature(ASExperimentalGraphicsContexts));
|
|
// We should get a callback here
|
|
// Now activate text node and expect it fails.
|
|
XCTAssertFalse(ASActivateExperimentalFeature(ASExperimentalTextNode));
|
|
// But we should get another callback.
|
|
[self waitForExpectationsWithTimeout:3 handler:nil];
|
|
}
|
|
|
|
#endif
|
|
|
|
- (void)textureDidActivateExperimentalFeatures:(ASExperimentalFeatures)feature
|
|
{
|
|
if (onActivate) {
|
|
onActivate(self, feature);
|
|
}
|
|
}
|
|
|
|
- (void)testMappingNamesToFlags
|
|
{
|
|
// Throw in a bad bit.
|
|
ASExperimentalFeatures allFeatures = [self allFeatures];
|
|
ASExperimentalFeatures featuresWithBadBit = allFeatures | (1 << 22);
|
|
NSArray *expectedNames = [ASConfigurationTests names];
|
|
XCTAssertEqualObjects(expectedNames, ASExperimentalFeaturesGetNames(featuresWithBadBit));
|
|
}
|
|
|
|
- (void)testMappingFlagsFromNames
|
|
{
|
|
// Throw in a bad name.
|
|
NSMutableArray *allNames = [[NSMutableArray alloc] initWithArray:[ASConfigurationTests names]];
|
|
[allNames addObject:@"__invalid_name"];
|
|
ASExperimentalFeatures expected = [self allFeatures];
|
|
XCTAssertEqual(expected, ASExperimentalFeaturesFromArray(allNames));
|
|
}
|
|
|
|
- (void)testFlagMatchName
|
|
{
|
|
NSArray *names = [ASConfigurationTests names];
|
|
for (NSInteger i = 0; i < names.count; i++) {
|
|
XCTAssertEqual(features[i], ASExperimentalFeaturesFromArray(@[names[i]]));
|
|
}
|
|
}
|
|
|
|
- (void)testNameMatchFlag {
|
|
NSArray *names = [ASConfigurationTests names];
|
|
for (NSInteger i = 0; i < names.count; i++) {
|
|
XCTAssertEqualObjects(@[names[i]], ASExperimentalFeaturesGetNames(features[i]));
|
|
}
|
|
}
|
|
|
|
@end
|