11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst dgram = require('dgram'); 61cb0ef41Sopenharmony_ciconst fork = require('child_process').fork; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst sock = dgram.createSocket('udp4'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst testNumber = parseInt(process.argv[2], 10); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst propertiesToTest = [ 131cb0ef41Sopenharmony_ci '_handle', 141cb0ef41Sopenharmony_ci '_receiving', 151cb0ef41Sopenharmony_ci '_bindState', 161cb0ef41Sopenharmony_ci '_queue', 171cb0ef41Sopenharmony_ci '_reuseAddr', 181cb0ef41Sopenharmony_ci]; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst methodsToTest = [ 211cb0ef41Sopenharmony_ci '_healthCheck', 221cb0ef41Sopenharmony_ci '_stopReceiving', 231cb0ef41Sopenharmony_ci]; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciconst propertyCases = propertiesToTest.map((propName) => { 261cb0ef41Sopenharmony_ci return [ 271cb0ef41Sopenharmony_ci () => { 281cb0ef41Sopenharmony_ci // Test property getter 291cb0ef41Sopenharmony_ci common.expectWarning( 301cb0ef41Sopenharmony_ci 'DeprecationWarning', 311cb0ef41Sopenharmony_ci `Socket.prototype.${propName} is deprecated`, 321cb0ef41Sopenharmony_ci 'DEP0112' 331cb0ef41Sopenharmony_ci ); 341cb0ef41Sopenharmony_ci sock[propName]; // eslint-disable-line no-unused-expressions 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci () => { 371cb0ef41Sopenharmony_ci // Test property setter 381cb0ef41Sopenharmony_ci common.expectWarning( 391cb0ef41Sopenharmony_ci 'DeprecationWarning', 401cb0ef41Sopenharmony_ci `Socket.prototype.${propName} is deprecated`, 411cb0ef41Sopenharmony_ci 'DEP0112' 421cb0ef41Sopenharmony_ci ); 431cb0ef41Sopenharmony_ci sock[propName] = null; 441cb0ef41Sopenharmony_ci }, 451cb0ef41Sopenharmony_ci ]; 461cb0ef41Sopenharmony_ci}); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciconst methodCases = methodsToTest.map((propName) => { 491cb0ef41Sopenharmony_ci return () => { 501cb0ef41Sopenharmony_ci common.expectWarning( 511cb0ef41Sopenharmony_ci 'DeprecationWarning', 521cb0ef41Sopenharmony_ci `Socket.prototype.${propName}() is deprecated`, 531cb0ef41Sopenharmony_ci 'DEP0112' 541cb0ef41Sopenharmony_ci ); 551cb0ef41Sopenharmony_ci sock[propName](); 561cb0ef41Sopenharmony_ci }; 571cb0ef41Sopenharmony_ci}); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciconst cases = [].concat( 601cb0ef41Sopenharmony_ci ...propertyCases, 611cb0ef41Sopenharmony_ci ...methodCases 621cb0ef41Sopenharmony_ci); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci// If we weren't passed a test ID then we need to spawn all of the cases. 651cb0ef41Sopenharmony_ci// We run the cases in child processes since deprecations print once. 661cb0ef41Sopenharmony_ciif (Number.isNaN(testNumber)) { 671cb0ef41Sopenharmony_ci const children = cases.map((_case, i) => 681cb0ef41Sopenharmony_ci fork(process.argv[1], [ String(i) ])); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci children.forEach((child) => { 711cb0ef41Sopenharmony_ci child.on('close', (code) => { 721cb0ef41Sopenharmony_ci // Pass on child exit code 731cb0ef41Sopenharmony_ci if (code > 0) { 741cb0ef41Sopenharmony_ci process.exit(code); 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci }); 771cb0ef41Sopenharmony_ci }); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci return; 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci// We were passed a test ID - run the test case 831cb0ef41Sopenharmony_ciassert.ok(cases[testNumber]); 841cb0ef41Sopenharmony_cicases[testNumber](); 85