|
| 1 | +// Flags: --expose-internals |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +require('../common'); |
| 5 | + |
| 6 | +// Test coverage for the updateOptionsBuffer method used internally |
| 7 | +// by the http2 implementation. |
| 8 | + |
| 9 | +const { updateOptionsBuffer } = require('internal/http2/util'); |
| 10 | +const { optionsBuffer } = process.binding('http2'); |
| 11 | +const { ok, strictEqual } = require('assert'); |
| 12 | + |
| 13 | +const IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE = 0; |
| 14 | +const IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS = 1; |
| 15 | +const IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH = 2; |
| 16 | +const IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS = 3; |
| 17 | +const IDX_OPTIONS_PADDING_STRATEGY = 4; |
| 18 | +const IDX_OPTIONS_FLAGS = 5; |
| 19 | + |
| 20 | +{ |
| 21 | + updateOptionsBuffer({ |
| 22 | + maxDeflateDynamicTableSize: 1, |
| 23 | + maxReservedRemoteStreams: 2, |
| 24 | + maxSendHeaderBlockLength: 3, |
| 25 | + peerMaxConcurrentStreams: 4, |
| 26 | + paddingStrategy: 5 |
| 27 | + }); |
| 28 | + |
| 29 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1); |
| 30 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2); |
| 31 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 3); |
| 32 | + strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4); |
| 33 | + strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5); |
| 34 | + |
| 35 | + const flags = optionsBuffer[IDX_OPTIONS_FLAGS]; |
| 36 | + |
| 37 | + ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE)); |
| 38 | + ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS)); |
| 39 | + ok(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH)); |
| 40 | + ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS)); |
| 41 | + ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY)); |
| 42 | +} |
| 43 | + |
| 44 | +{ |
| 45 | + optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH] = 0; |
| 46 | + |
| 47 | + updateOptionsBuffer({ |
| 48 | + maxDeflateDynamicTableSize: 1, |
| 49 | + maxReservedRemoteStreams: 2, |
| 50 | + peerMaxConcurrentStreams: 4, |
| 51 | + paddingStrategy: 5 |
| 52 | + }); |
| 53 | + |
| 54 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1); |
| 55 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2); |
| 56 | + strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 0); |
| 57 | + strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4); |
| 58 | + strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5); |
| 59 | + |
| 60 | + const flags = optionsBuffer[IDX_OPTIONS_FLAGS]; |
| 61 | + |
| 62 | + ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE)); |
| 63 | + ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS)); |
| 64 | + ok(!(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH))); |
| 65 | + ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS)); |
| 66 | + ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY)); |
| 67 | +} |
0 commit comments