Skip to content

Commit

Permalink
Re-sync with internal repository (#633)
Browse files Browse the repository at this point in the history
The internal and external repositories are out of sync. This Pull Request attempts to brings them back in sync by patching the GitHub repository. Please carefully review this patch. You must disable ShipIt for your project in order to merge this pull request. DO NOT IMPORT this pull request. Instead, merge it directly on GitHub using the MERGE BUTTON. Re-enable ShipIt after merging.
  • Loading branch information
facebook-github-bot authored Jan 9, 2025
1 parent 7af2e5a commit cb8a0f6
Show file tree
Hide file tree
Showing 37 changed files with 199 additions and 32 deletions.
2 changes: 1 addition & 1 deletion thrift/lib/hack/src/TClientAsyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TClientAsyncHandler {
string $service_name,
string $func_name,
?IThriftStruct $args = null,
)[zoned_local]: Awaitable<void> {
): Awaitable<void> {
// Do nothing
}

Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/hack/src/TClientMultiAsyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getHandlers()[]: readonly dict<string, TClientAsyncHandler> {
string $service_name,
string $func_name,
?IThriftStruct $args = null,
)[zoned_shallow]: Awaitable<void> {
): Awaitable<void> {
await Vec\map_async(
$this->handlers,
async $handler ==>
Expand Down
46 changes: 23 additions & 23 deletions thrift/lib/hack/src/TContextPropV2ServerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ public function preWrite(
string $fn_name,
mixed $result,
): void {
// keeping this logic in tact from v1 and not moving it to handlers
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
if (
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
) {
$context_manager = ContextManager::get();
if ($context_manager->getCoreContext() !== null) {
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());

if (
C\contains_key(
$ctx_prop_headers,
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
)
) {
$this->thriftServer->addHTTPHeader(
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
);
}
}
}

$full_params = $this->params;
$full_params['fn_name'] = $fn_name;
$full_params['fn_result'] = $result;
Expand Down Expand Up @@ -68,29 +91,6 @@ public function preWrite(
HTTPResponseHeader::THRIFT_FRAMEWORK_METADATA_RESPONSE,
$encoded_response_tfm,
);

// keeping this logic in tact from v1 and not moving it to handlers
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
if (
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
) {
$context_manager = ContextManager::get();
if ($context_manager->getCoreContext() !== null) {
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());

if (
C\contains_key(
$ctx_prop_headers,
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
)
) {
$this->thriftServer->addHTTPHeader(
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
);
}
}
}
}

}
47 changes: 47 additions & 0 deletions thrift/lib/hack/src/ThriftContextPropState.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,53 @@ public function getModelTypeId()[]: ?int {
return $this->getModelInfo()?->get_model_type_id();
}

// user id getters
public function getUserIds()[]: ?ContextProp\UserIds {
return $this->getBaggage()?->user_ids;
}

public function getFBUserId()[]: ?int {
return $this->getUserIds()?->fb_user_id;
}

public function getIGUserId()[]: ?int {
return $this->getUserIds()?->ig_user_id;
}

// user id setters
public function setUserIds(
?ContextProp\UserIds $user_ids,
)[write_props]: void {
$this->storage->baggage =
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();

$baggage = $this->storage->baggage as nonnull;
$baggage->user_ids = $user_ids;
$this->dirty();
}

public function setFBUserId(int $fb_user_id)[write_props]: void {
$this->storage->baggage =
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
$baggage = $this->storage->baggage as nonnull;

$baggage->user_ids =
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
$baggage->user_ids->fb_user_id = $fb_user_id;
$this->dirty();
}

public function setIGUserId(int $ig_user_id)[write_props]: void {
$this->storage->baggage =
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
$baggage = $this->storage->baggage as nonnull;

$baggage->user_ids =
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
$baggage->user_ids->ig_user_id = $ig_user_id;
$this->dirty();
}

public function getTraceContext()[]: ?ContextProp\TraceContext {
if ($this->storage->baggage is nonnull) {
$trace_context = $this->storage->baggage?->trace_context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ final class BacktraceClientEventHandlerTest extends WWWTest {

<<Oncalls('xdc_artillery')>>
final class ThriftBacktraceServerEventHandlerTest extends WWWTest {
use ClassLevelTest;
public async function testSetsHeaderWhenBacktraceActive(): Awaitable<void> {
$thrift_server = mock(ThriftServer::class);
$handler = new ThriftBacktraceServerEventHandler($thrift_server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<<Oncalls('thrift')>>
final class ThriftContextPropHandlerTest extends WWWTest {
use ClassLevelTest;
private static function readTFMForTest(string $v): ThriftFrameworkMetadata {
$transport = Base64::decode($v);
$buf = new TMemoryBuffer($transport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<<Oncalls('xdc_artillery')>>
final class ThriftContextPropServerEventHandlerTest extends WWWTest {
use ClassLevelTest;
public async function testThriftContextPropResponsePath(): Awaitable<void> {
ThriftContextPropState::get()->addExperimentId(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<<Oncalls('xdc_artillery')>>
final class ThriftContextPropStateScopeGuardTest extends WWWTest {

use ClassLevelTest;

private function getSerializedTFMHeaders(
string $overriden_request_id,
int $overriden_origin_id,
Expand Down
34 changes: 34 additions & 0 deletions thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<<Oncalls('thrift')>>
final class ThriftContextPropStateTest extends WWWTest {
use ClassLevelTest;
public function testAccess(): void {
$tcps = ThriftContextPropState::get();
expect($tcps->getRequestId())->toEqual("");
Expand Down Expand Up @@ -37,6 +38,39 @@ public function testRegionalizationEntityNullable(): void {
expect($tcps->getRegionalizationEntity())->toBeNull();
}

public function testUserIdsNullable(): void {
$tcps = ThriftContextPropState::get();
expect($tcps->getUserIds())->toBeNull();

// 0 is different from null
$tcps->setUserIds(ContextProp\UserIds::withDefaultValues());
expect($tcps->getUserIds())->toNotBeNull();
expect($tcps->getUserIds()?->fb_user_id)->toEqual(0);
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);

// override existing value
$tcps->setUserIds(new ContextProp\UserIds(1, 2));
expect($tcps->getUserIds()?->fb_user_id)->toEqual(1);
expect($tcps->getUserIds()?->ig_user_id)->toEqual(2);

// back to null
$tcps->setUserIds(null);
expect($tcps->getUserIds())->toBeNull();

// set FB Id only
$tcps->setFBUserId(3);
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
expect($tcps->getFBUserId())->toEqual(3);
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);

// set IG Id only
$tcps->setIGUserId(4);
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
expect($tcps->getUserIds()?->ig_user_id)->toEqual(4);
expect($tcps->getIGUserId())->toEqual(4);

}

public function testBaggage(): void {
$tcps = ThriftContextPropState::get();
$tcps->clear();
Expand Down
2 changes: 2 additions & 0 deletions thrift/lib/hack/src/__tests__/ThriftImmutableWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<<Oncalls('signals_infra')>>
final class ThriftImmutableWrapperTest extends WWWTest {

use ClassLevelTest;

public async function testGetSerializedThrift(): Awaitable<void> {
$underlying = AdsConsentPlatformParams::fromShape(shape(
'traceID' => '123',
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/hack/src/__tests__/ThriftPolicyEnforcerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<<Oncalls('www_privacy_frameworks')>>
final class ThriftPolicyEnforcerTest extends WWWTest {
use ClassLevelTest;
use TPolicyEnforcerTest;

const int FAKE_CALLER_0 = 0;
Expand All @@ -15,7 +16,6 @@ final class ThriftPolicyEnforcerTest extends WWWTest {
public async function beforeEach(): Awaitable<void> {
MockJustKnobs::setInt('privacy:emergency_sampling_backoff_www', 1);
MockPZ2::disableSampling();
MockPZ::alwaysLog();
MockPrivacyLib::neverDisableLibrary();
}

Expand Down
2 changes: 2 additions & 0 deletions thrift/lib/hack/src/__tests__/ThriftUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<<Oncalls('thrift')>>
final class ThriftUtilTest extends WWWTest {

use ClassLevelTest;

public async function testGetUnionTypeFromShape(): Awaitable<void> {
expect(
ThriftUtil::getUnionTypeFromShape<
Expand Down
4 changes: 4 additions & 0 deletions thrift/lib/hack/src/conformance/__tests__/LazyAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<<Oncalls('search_topaggr'), Feature('FBApp_Search_IndexServe')>>
final class LazyAnyTest extends LazyAnyTestBase {

use ClassLevelTest;

const classname<IThriftStruct> CLASSNAME = unicorn_test_MainStruct::class;
const classname<TProtocolSerializer> DATA_SERIALIZER =
TCompactSerializer::class;
Expand All @@ -15,6 +17,8 @@ final class LazyAnyTest extends LazyAnyTestBase {
<<Oncalls('search_topaggr'), Feature('FBApp_Search_IndexServe')>>
final class LazyAnySimpleJsonTest extends LazyAnyTestBase {

use ClassLevelTest;

const classname<IThriftStruct> CLASSNAME =
unicorn_test_MainStructSimpleJson::class;
const classname<TProtocolSerializer> DATA_SERIALIZER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<<Oncalls('smint')>>
final class ThriftTypeStructAdapterTest extends WWWTest {
use ClassLevelTest;
public async function testFromHackType(): Awaitable<void> {
// Struct type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<<Oncalls('thrift')>>
final class ThriftUniversalNameTest extends WWWTest {
use ClassLevelTest;
public async function testUniversalHashSha256(): Awaitable<void> {
$expected = non_crypto_sha256("fbthrift://foo.com/my/type", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
final class ThriftLazyAnyTestForStruct
extends ThriftLazyAnyTestBase<facebook\thrift\test\ExampleStruct> {

use ClassLevelTest;

const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
'type' => TType::STRUCT,
'class' => facebook\thrift\test\ExampleStruct::class,
Expand Down Expand Up @@ -45,6 +47,8 @@ protected static function getValueFromLazyAny(
<<Oncalls('thrift')>>
final class ThriftLazyAnyTestForString extends ThriftLazyAnyTestBase<string> {

use ClassLevelTest;

const ThriftStructGenericSpecImpl TYPE_SPEC = shape('type' => TType::STRING);

const self::TPerProtocolSerializedStrings CPP_HEX_BINARY_SERIALIZED_STRINGS =
Expand Down Expand Up @@ -76,6 +80,8 @@ protected static function getValueFromLazyAny(ThriftLazyAny $any): ?string {
final class ThriftLazyAnyTestForEnum
extends ThriftLazyAnyTestBase<facebook\thrift\test\ExampleEnum> {

use ClassLevelTest;

const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
'type' => TType::I32,
'enum' => facebook\thrift\test\ExampleEnum::class,
Expand Down Expand Up @@ -114,6 +120,8 @@ protected static function getValueFromLazyAny(
final class ThriftLazyAnyTestForContainer
extends ThriftLazyAnyTestBase<dict<int, string>> {

use ClassLevelTest;

const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
'type' => TType::MAP,
'key' => shape('type' => TType::I32),
Expand Down Expand Up @@ -154,6 +162,8 @@ protected static function getValueFromLazyAny(
<<Oncalls('thrift')>>
final class ThriftLazyAnyTestForBool extends ThriftLazyAnyTestBase<bool> {

use ClassLevelTest;

const ThriftStructGenericSpecImpl TYPE_SPEC = shape('type' => TType::BOOL);

const self::TPerProtocolSerializedStrings CPP_HEX_BINARY_SERIALIZED_STRINGS =
Expand Down Expand Up @@ -189,6 +199,7 @@ final class ThriftLazyAnyTestForNestedStructInContainers
facebook\thrift\test\ExampleStruct,
>>,
> {
use ClassLevelTest;
const type THackType = dict<
int,
dict<facebook\thrift\test\ExampleEnum, facebook\thrift\test\ExampleStruct>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<<Oncalls('xdc_artillery')>>
final class ExperimentIdContextHandlerTest extends WWWTest {

use ClassLevelTest;

<<__Override>>
public async function beforeEach(): Awaitable<void> {
ThriftContextPropState::get()->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<<Oncalls('xdc_artillery')>>
final class UpdateUniverseContextHandlerTest extends WWWTest {

use ClassLevelTest;

<<__Override>>
public async function beforeEach(): Awaitable<void> {
clear_class_memoization(PrivacyLibKS::class, 'isKilled');
Expand Down Expand Up @@ -173,7 +175,7 @@ classname<IThriftClient> $thrift_service_name,

private async function genInitPZ2(): Awaitable<void> {
await MockPZ2::genInitRequest(
PZ2StaticCodeAnnotation::get()->withPolicy(
PZ2CodeAnnotationStatic::get()->withPolicy(
PZ2XSUPolicy::create(PZ2XSUStates::FACEBOOK),
),
);
Expand Down
1 change: 1 addition & 0 deletions thrift/lib/hack/src/protocol/__tests__/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<<Oncalls('thrift')>>
final class AdapterTest extends WWWTest {
use ClassLevelTest;
public static function getTestCases(
): dict<string, (AdapterTest\Foo, AdapterTest\FooWithoutAdapters)> {
return dict[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<<Oncalls('thrift')>>
final class FieldWrapperTest extends WWWTest {
use ClassLevelTest;
public static async function genTestCases(
): Awaitable<dict<string, vec<FieldWrapperTest\MyStruct>>> {
return dict[
Expand Down
12 changes: 12 additions & 0 deletions thrift/lib/hack/src/protocol/__tests__/ProtocolTest.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ struct TestTerseWriteStruct {
11: set<i32> set_of_ints;
12: map<string, ComplexStruct> map_of_str_to_struct;
}

struct CorruptedDataStruct1 {
1: list<string> string_list;
2: set<string> string_set;
3: map<string, i64> string_i64_map;
}

struct CorruptedDataStruct2 {
1: list<i64> i64_list;
2: set<i64> i64_set;
3: map<i64, i64> i64_i64_map;
}
Loading

0 comments on commit cb8a0f6

Please sign in to comment.