This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept partially updated newRequest messages
Summary: # Context D64736668 changed IG4A to send two `newRequest` commands with the same ID: the first one when the request starts, and the second one when the request body finished. This caused request bodies to disappear from Flipper. D66176444 reverted the IG4A change. https://fb.workplace.com/groups/503431980400629/posts/1800245397385941/?comment_id=1800491244028023 # This diff Handle repeated `newRequest` command Flipper-side. Reviewed By: LukeDefeo Differential Revision: D66232498 fbshipit-source-id: 3ab58dff5986485782f8d66394f9d3a154ea82b7
- Loading branch information
1 parent
a925604
commit eb05e53
Showing
2 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
desktop/plugins/public/network/__tests__/datastorage.node.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
import {createDataSource} from 'flipper-plugin'; | ||
import {RequestDataDB} from '../RequestDataDB'; | ||
import {createRequestFromRequestInfo} from '../index'; | ||
|
||
import {decodeBody} from '../utils'; | ||
|
||
import {Request} from '../types'; | ||
import {Base64} from 'js-base64'; | ||
|
||
// IndexedDB polyfill | ||
global.structuredClone = (val) => (val ? JSON.parse(JSON.stringify(val)) : val); | ||
require('fake-indexeddb/auto'); | ||
|
||
const firstRequest = { | ||
id: '17', | ||
timestamp: 1234567890, | ||
method: 'GET', | ||
url: 'https://fbflipper.com/', | ||
headers: [{key: 'Content-Type', value: 'text/plain'}], | ||
data: undefined, | ||
}; | ||
|
||
const secondRequest = { | ||
id: '17', | ||
timestamp: 1234567890, | ||
method: 'GET', // same as before | ||
url: 'https://fallback.fbflipper.com/', // changed from before | ||
headers: [{key: 'Content-Type', value: 'text/plain'}], | ||
data: Base64.encode('hello world'), // new field (not stored in DataSource) | ||
}; | ||
|
||
test('DataSource handles updates', () => { | ||
const requests = createDataSource<Request, 'id'>([], { | ||
key: 'id', | ||
indices: [['method'], ['status']], | ||
}); | ||
const customColumns = []; | ||
|
||
requests.upsert(createRequestFromRequestInfo(firstRequest, customColumns)); | ||
requests.upsert(createRequestFromRequestInfo(secondRequest, customColumns)); | ||
|
||
const result = requests.getById('17'); | ||
expect(result?.method).toEqual('GET'); | ||
expect(result?.url).toEqual('https://fallback.fbflipper.com/'); | ||
}); | ||
|
||
test('RequestDataDB handles updates', async () => { | ||
const db = new RequestDataDB(); | ||
|
||
db.storeRequestData( | ||
firstRequest.id, | ||
decodeBody(firstRequest.headers, firstRequest.data), | ||
); | ||
db.storeRequestData( | ||
secondRequest.id, | ||
decodeBody(secondRequest.headers, secondRequest.data), | ||
); | ||
|
||
const result = await db.getRequestData('17'); | ||
expect(result).toEqual('hello world'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters