Files
bun.sh/test/js/third_party/grpc-js/assert2.ts
Ciro Spaciari c23579d66c feat(http2) Client Support (#6761)
* init

* WIP fix post data/refactor

* make it compile again

* more things

* undo padding and continue + fix posting + update lshpack

* re-add fixes

* really simple tests + fixes

* add aborted event

* fix trailers

* add getDefaultSettings, getPackedSettings and getUnpackedSettings

* fix + fmt

* fixes

* fix enablePush o be boolean

* fix sendTrailers

* fmt

* fix goaway, fix some error messages

* oops

* revert some changes

* more reverts

* WIP

* get CMAKE building lspack + ping behavior

* remove files that should not be added anymore

* remove old out files

* remove old file

* fix header reduce

* bunch of fixes

* fix socket unref

* fix abort signal, rebase and fmt

* socket unref tests

* oops re-add cmake

* fix stream state

* more tests and fixes

* fixes and ping tests

* lshpack in Dockerfile

* just copy lshpack

* oops

* fix end

* wantTrailers

* encode/decode fixes + grpc

* channel credentials test

* rebase

* support h2c

* fix h2c

* fix h2c connect event + h2c tests

* 'copy ls-hpack

* ls-hpack build sh

* oops

* changing CMake + Docker

* add ps1 build for ls-hpack fix clean

* optimizations + fixes

* remove protect/unprotect from handlers

* more consistent errors

* fix error code

* oops

* add goaway tests

* oops uncoment tests

* better errors more tests

* add broken priority frame

* better memory leak, some fixes and less flask tests

* zig update .Big -> .big

* closer threshold + h2 fix

* remove log

* test should not be flask

* increase timeout on leak memory test

* windows build

* less flasky

* always 127.0.0.1

* [autofix.ci] apply automated fixes

* remove .call and use primordials

* apply socket fix

* fix win-build

* should properly mark inactive

* postgres fix

* increase deadline

* test tests

* high light deadline timeouts

* event loop test

* make memory leak test faster

* use buffer on payload test

* check for socket.data before use

* reduce iterations to see if timeout on mac intel

* fix assertions

* avoid localhost and simplify things

* refactor memory leak test

* Update src/js/node/tls.js

* fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: cirospaciari <ciro.spaciai@gmail.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-11-17 18:14:54 -08:00

94 lines
2.4 KiB
TypeScript

/*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import assert from "assert";
const toCall = new Map<() => void, number>();
const afterCallsQueue: Array<() => void> = [];
/**
* Assert that the given function doesn't throw an error, and then return
* its value.
* @param fn The function to evaluate.
*/
export function noThrowAndReturn<T>(fn: () => T): T {
try {
return fn();
} catch (e) {
assert.throws(() => {
throw e;
});
throw e; // for type safety only
}
}
/**
* Helper function that returns true when every function wrapped with
* mustCall has been called.
*/
function mustCallsSatisfied(): boolean {
let result = true;
toCall.forEach(value => {
result = result && value === 0;
});
return result;
}
export function clearMustCalls(): void {
afterCallsQueue.length = 0;
}
/**
* Wraps a function to keep track of whether it was called or not.
* @param fn The function to wrap.
*/
// tslint:disable:no-any
export function mustCall<T>(fn: (...args: any[]) => T): (...args: any[]) => T {
const existingValue = toCall.get(fn);
if (existingValue !== undefined) {
toCall.set(fn, existingValue + 1);
} else {
toCall.set(fn, 1);
}
return (...args: any[]) => {
const result = fn(...args);
const existingValue = toCall.get(fn);
if (existingValue !== undefined) {
toCall.set(fn, existingValue - 1);
}
if (mustCallsSatisfied()) {
afterCallsQueue.forEach(fn => fn());
afterCallsQueue.length = 0;
}
return result;
};
}
/**
* Calls the given function when every function that was wrapped with
* mustCall has been called.
* @param fn The function to call once all mustCall-wrapped functions have
* been called.
*/
export function afterMustCallsSatisfied(fn: () => void): void {
if (!mustCallsSatisfied()) {
afterCallsQueue.push(fn);
} else {
fn();
}
}