11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst checkWeight = (actual, expect) => { 101cb0ef41Sopenharmony_ci const server = http2.createServer(); 111cb0ef41Sopenharmony_ci server.on('stream', common.mustCall((stream, headers, flags) => { 121cb0ef41Sopenharmony_ci assert.strictEqual(stream.state.weight, expect); 131cb0ef41Sopenharmony_ci stream.respond(); 141cb0ef41Sopenharmony_ci stream.end('test'); 151cb0ef41Sopenharmony_ci })); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 181cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 191cb0ef41Sopenharmony_ci const req = client.request({}, { weight: actual }); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci req.on('data', common.mustCall()); 221cb0ef41Sopenharmony_ci req.on('end', common.mustCall()); 231cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 241cb0ef41Sopenharmony_ci server.close(); 251cb0ef41Sopenharmony_ci client.close(); 261cb0ef41Sopenharmony_ci })); 271cb0ef41Sopenharmony_ci })); 281cb0ef41Sopenharmony_ci}; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci// When client weight is lower than 1, weight is 1 311cb0ef41Sopenharmony_cicheckWeight(-1, 1); 321cb0ef41Sopenharmony_cicheckWeight(0, 1); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci// 1 - 256 is correct weight 351cb0ef41Sopenharmony_cicheckWeight(1, 1); 361cb0ef41Sopenharmony_cicheckWeight(16, 16); 371cb0ef41Sopenharmony_cicheckWeight(256, 256); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci// When client weight is higher than 256, weight is 256 401cb0ef41Sopenharmony_cicheckWeight(257, 256); 411cb0ef41Sopenharmony_cicheckWeight(512, 256); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci// When client weight is undefined, weight is default 16 441cb0ef41Sopenharmony_cicheckWeight(undefined, 16); 45