Skip to content

Commit 24a43da

Browse files
Re-sync with internal repository (facebook#9577)
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.
1 parent 75c1143 commit 24a43da

40 files changed

+360
-149
lines changed

third-party/thrift/src/thrift/lib/hack/src/TClientAsyncHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TClientAsyncHandler {
3434
string $service_name,
3535
string $func_name,
3636
?IThriftStruct $args = null,
37-
)[zoned_local]: Awaitable<void> {
37+
): Awaitable<void> {
3838
// Do nothing
3939
}
4040

third-party/thrift/src/thrift/lib/hack/src/TClientMultiAsyncHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getHandlers()[]: readonly dict<string, TClientAsyncHandler> {
5252
string $service_name,
5353
string $func_name,
5454
?IThriftStruct $args = null,
55-
)[zoned_shallow]: Awaitable<void> {
55+
): Awaitable<void> {
5656
await Vec\map_async(
5757
$this->handlers,
5858
async $handler ==>

third-party/thrift/src/thrift/lib/hack/src/TContextPropV2ServerHandler.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ public function preWrite(
4141
string $fn_name,
4242
mixed $result,
4343
): void {
44+
// keeping this logic in tact from v1 and not moving it to handlers
45+
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
46+
if (
47+
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
48+
) {
49+
$context_manager = ContextManager::get();
50+
if ($context_manager->getCoreContext() !== null) {
51+
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());
52+
53+
if (
54+
C\contains_key(
55+
$ctx_prop_headers,
56+
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
57+
)
58+
) {
59+
$this->thriftServer->addHTTPHeader(
60+
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
61+
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
62+
);
63+
}
64+
}
65+
}
66+
4467
$full_params = $this->params;
4568
$full_params['fn_name'] = $fn_name;
4669
$full_params['fn_result'] = $result;
@@ -68,29 +91,6 @@ public function preWrite(
6891
HTTPResponseHeader::THRIFT_FRAMEWORK_METADATA_RESPONSE,
6992
$encoded_response_tfm,
7093
);
71-
72-
// keeping this logic in tact from v1 and not moving it to handlers
73-
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
74-
if (
75-
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
76-
) {
77-
$context_manager = ContextManager::get();
78-
if ($context_manager->getCoreContext() !== null) {
79-
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());
80-
81-
if (
82-
C\contains_key(
83-
$ctx_prop_headers,
84-
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
85-
)
86-
) {
87-
$this->thriftServer->addHTTPHeader(
88-
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
89-
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
90-
);
91-
}
92-
}
93-
}
9494
}
9595

9696
}

third-party/thrift/src/thrift/lib/hack/src/ThriftContextPropState.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,53 @@ public function getModelTypeId()[]: ?int {
233233
return $this->getModelInfo()?->get_model_type_id();
234234
}
235235

236+
// user id getters
237+
public function getUserIds()[]: ?ContextProp\UserIds {
238+
return $this->getBaggage()?->user_ids;
239+
}
240+
241+
public function getFBUserId()[]: ?int {
242+
return $this->getUserIds()?->fb_user_id;
243+
}
244+
245+
public function getIGUserId()[]: ?int {
246+
return $this->getUserIds()?->ig_user_id;
247+
}
248+
249+
// user id setters
250+
public function setUserIds(
251+
?ContextProp\UserIds $user_ids,
252+
)[write_props]: void {
253+
$this->storage->baggage =
254+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
255+
256+
$baggage = $this->storage->baggage as nonnull;
257+
$baggage->user_ids = $user_ids;
258+
$this->dirty();
259+
}
260+
261+
public function setFBUserId(int $fb_user_id)[write_props]: void {
262+
$this->storage->baggage =
263+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
264+
$baggage = $this->storage->baggage as nonnull;
265+
266+
$baggage->user_ids =
267+
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
268+
$baggage->user_ids->fb_user_id = $fb_user_id;
269+
$this->dirty();
270+
}
271+
272+
public function setIGUserId(int $ig_user_id)[write_props]: void {
273+
$this->storage->baggage =
274+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
275+
$baggage = $this->storage->baggage as nonnull;
276+
277+
$baggage->user_ids =
278+
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
279+
$baggage->user_ids->ig_user_id = $ig_user_id;
280+
$this->dirty();
281+
}
282+
236283
public function getTraceContext()[]: ?ContextProp\TraceContext {
237284
if ($this->storage->baggage is nonnull) {
238285
$trace_context = $this->storage->baggage?->trace_context;

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftBacktraceEventHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ final class BacktraceClientEventHandlerTest extends WWWTest {
6969

7070
<<Oncalls('xdc_artillery')>>
7171
final class ThriftBacktraceServerEventHandlerTest extends WWWTest {
72+
use ClassLevelTest;
7273
public async function testSetsHeaderWhenBacktraceActive(): Awaitable<void> {
7374
$thrift_server = mock(ThriftServer::class);
7475
$handler = new ThriftBacktraceServerEventHandler($thrift_server);

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('thrift')>>
55
final class ThriftContextPropHandlerTest extends WWWTest {
6+
use ClassLevelTest;
67
private static function readTFMForTest(string $v): ThriftFrameworkMetadata {
78
$transport = Base64::decode($v);
89
$buf = new TMemoryBuffer($transport);

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropServerEventHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropStateScopeGuardTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<<Oncalls('xdc_artillery')>>
55
final class ThriftContextPropStateScopeGuardTest extends WWWTest {
66

7+
use ClassLevelTest;
8+
79
private function getSerializedTFMHeaders(
810
string $overriden_request_id,
911
int $overriden_origin_id,

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('thrift')>>
55
final class ThriftContextPropStateTest extends WWWTest {
6+
use ClassLevelTest;
67
public function testAccess(): void {
78
$tcps = ThriftContextPropState::get();
89
expect($tcps->getRequestId())->toEqual("");
@@ -37,6 +38,39 @@ public function testRegionalizationEntityNullable(): void {
3738
expect($tcps->getRegionalizationEntity())->toBeNull();
3839
}
3940

41+
public function testUserIdsNullable(): void {
42+
$tcps = ThriftContextPropState::get();
43+
expect($tcps->getUserIds())->toBeNull();
44+
45+
// 0 is different from null
46+
$tcps->setUserIds(ContextProp\UserIds::withDefaultValues());
47+
expect($tcps->getUserIds())->toNotBeNull();
48+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(0);
49+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);
50+
51+
// override existing value
52+
$tcps->setUserIds(new ContextProp\UserIds(1, 2));
53+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(1);
54+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(2);
55+
56+
// back to null
57+
$tcps->setUserIds(null);
58+
expect($tcps->getUserIds())->toBeNull();
59+
60+
// set FB Id only
61+
$tcps->setFBUserId(3);
62+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
63+
expect($tcps->getFBUserId())->toEqual(3);
64+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);
65+
66+
// set IG Id only
67+
$tcps->setIGUserId(4);
68+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
69+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(4);
70+
expect($tcps->getIGUserId())->toEqual(4);
71+
72+
}
73+
4074
public function testBaggage(): void {
4175
$tcps = ThriftContextPropState::get();
4276
$tcps->clear();

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftImmutableWrapperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<<Oncalls('signals_infra')>>
55
final class ThriftImmutableWrapperTest extends WWWTest {
66

7+
use ClassLevelTest;
8+
79
public async function testGetSerializedThrift(): Awaitable<void> {
810
$underlying = AdsConsentPlatformParams::fromShape(shape(
911
'traceID' => '123',

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftPolicyEnforcerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<<Oncalls('www_privacy_frameworks')>>
66
final class ThriftPolicyEnforcerTest extends WWWTest {
7+
use ClassLevelTest;
78
use TPolicyEnforcerTest;
89

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

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftUtilTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<<Oncalls('thrift')>>
2020
final class ThriftUtilTest extends WWWTest {
2121

22+
use ClassLevelTest;
23+
2224
public async function testGetUnionTypeFromShape(): Awaitable<void> {
2325
expect(
2426
ThriftUtil::getUnionTypeFromShape<

third-party/thrift/src/thrift/lib/hack/src/conformance/__tests__/LazyAnyTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<<Oncalls('search_topaggr'), Feature('FBApp_Search_IndexServe')>>
55
final class LazyAnyTest extends LazyAnyTestBase {
66

7+
use ClassLevelTest;
8+
79
const classname<IThriftStruct> CLASSNAME = unicorn_test_MainStruct::class;
810
const classname<TProtocolSerializer> DATA_SERIALIZER =
911
TCompactSerializer::class;
@@ -15,6 +17,8 @@ final class LazyAnyTest extends LazyAnyTestBase {
1517
<<Oncalls('search_topaggr'), Feature('FBApp_Search_IndexServe')>>
1618
final class LazyAnySimpleJsonTest extends LazyAnyTestBase {
1719

20+
use ClassLevelTest;
21+
1822
const classname<IThriftStruct> CLASSNAME =
1923
unicorn_test_MainStructSimpleJson::class;
2024
const classname<TProtocolSerializer> DATA_SERIALIZER =

third-party/thrift/src/thrift/lib/hack/src/conformance/__tests__/ThriftTypeStructAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('smint')>>
55
final class ThriftTypeStructAdapterTest extends WWWTest {
6+
use ClassLevelTest;
67
public async function testFromHackType(): Awaitable<void> {
78
// Struct type
89

third-party/thrift/src/thrift/lib/hack/src/conformance/__tests__/ThriftUniversalNameTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

third-party/thrift/src/thrift/lib/hack/src/conformance/__tests__/thrift_any/ThriftLazyAnyTests.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
final class ThriftLazyAnyTestForStruct
66
extends ThriftLazyAnyTestBase<facebook\thrift\test\ExampleStruct> {
77

8+
use ClassLevelTest;
9+
810
const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
911
'type' => TType::STRUCT,
1012
'class' => facebook\thrift\test\ExampleStruct::class,
@@ -45,6 +47,8 @@ protected static function getValueFromLazyAny(
4547
<<Oncalls('thrift')>>
4648
final class ThriftLazyAnyTestForString extends ThriftLazyAnyTestBase<string> {
4749

50+
use ClassLevelTest;
51+
4852
const ThriftStructGenericSpecImpl TYPE_SPEC = shape('type' => TType::STRING);
4953

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

83+
use ClassLevelTest;
84+
7985
const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
8086
'type' => TType::I32,
8187
'enum' => facebook\thrift\test\ExampleEnum::class,
@@ -114,6 +120,8 @@ protected static function getValueFromLazyAny(
114120
final class ThriftLazyAnyTestForContainer
115121
extends ThriftLazyAnyTestBase<dict<int, string>> {
116122

123+
use ClassLevelTest;
124+
117125
const ThriftStructGenericSpecImpl TYPE_SPEC = shape(
118126
'type' => TType::MAP,
119127
'key' => shape('type' => TType::I32),
@@ -154,6 +162,8 @@ protected static function getValueFromLazyAny(
154162
<<Oncalls('thrift')>>
155163
final class ThriftLazyAnyTestForBool extends ThriftLazyAnyTestBase<bool> {
156164

165+
use ClassLevelTest;
166+
157167
const ThriftStructGenericSpecImpl TYPE_SPEC = shape('type' => TType::BOOL);
158168

159169
const self::TPerProtocolSerializedStrings CPP_HEX_BINARY_SERIALIZED_STRINGS =
@@ -189,6 +199,7 @@ final class ThriftLazyAnyTestForNestedStructInContainers
189199
facebook\thrift\test\ExampleStruct,
190200
>>,
191201
> {
202+
use ClassLevelTest;
192203
const type THackType = dict<
193204
int,
194205
dict<facebook\thrift\test\ExampleEnum, facebook\thrift\test\ExampleStruct>,

0 commit comments

Comments
 (0)