@@ -28,12 +28,7 @@ import * as zlib from 'zlib';
2828
2929import { perftools } from 'pprof/proto/profile' ;
3030import { ProfilerConfig } from '../src/config' ;
31- import {
32- parseBackoffDuration ,
33- Profiler ,
34- Retryer ,
35- BackoffResponseError ,
36- } from '../src/profiler' ;
31+ import { Profiler , Retryer , BackoffResponseError } from '../src/profiler' ;
3732
3833import {
3934 decodedHeapProfile ,
@@ -42,7 +37,7 @@ import {
4237 timeProfile ,
4338} from './profiles-for-tests' ;
4439
45- import parseDuration from 'parse-duration ' ;
40+ import * as ms from 'ms ' ;
4641// eslint-disable-next-line @typescript-eslint/no-var-requires
4742const fakeCredentials = require ( '../../test/fixtures/gcloud-credentials.json' ) ;
4843
@@ -66,9 +61,9 @@ const testConfig: ProfilerConfig = {
6661 heapMaxStackDepth : 64 ,
6762 ignoreHeapSamplesPath : '@google-cloud/profiler' ,
6863 initialBackoffMillis : 1000 ,
69- backoffCapMillis : parseDuration ( '1h' ) ! ,
64+ backoffCapMillis : ms ( '1h' ) ! ,
7065 backoffMultiplier : 1.3 ,
71- serverBackoffCapMillis : parseDuration ( '7d' ) ! ,
66+ serverBackoffCapMillis : ms ( '7d' ) ! ,
7267 localProfilingPeriodMillis : 1000 ,
7368 localTimeDurationMillis : 1000 ,
7469 localLogPeriodMillis : 1000 ,
@@ -891,7 +886,7 @@ describe('Profiler', () => {
891886 ) ;
892887 const profiler = new Profiler ( testConfig ) ;
893888 const delayMillis = await profiler . collectProfile ( ) ;
894- assert . strictEqual ( parseDuration ( '7d' ) , delayMillis ) ;
889+ assert . strictEqual ( ms ( '7d' ) , delayMillis ) ;
895890 }
896891 ) ;
897892 it (
@@ -919,48 +914,4 @@ describe('Profiler', () => {
919914 }
920915 ) ;
921916 } ) ;
922- describe ( 'parseBackoffDuration' , ( ) => {
923- it ( 'should return undefined when no duration specified' , ( ) => {
924- assert . strictEqual ( undefined , parseBackoffDuration ( '' ) ) ;
925- } ) ;
926- it ( 'should parse backoff with minutes and seconds specified' , ( ) => {
927- assert . strictEqual (
928- 62000 ,
929- parseBackoffDuration ( 'action throttled, backoff for 1m2s' )
930- ) ;
931- } ) ;
932- it ( 'should parse backoff with fraction of second' , ( ) => {
933- assert . strictEqual (
934- 2500 ,
935- parseBackoffDuration ( 'action throttled, backoff for 2.5s' )
936- ) ;
937- } ) ;
938- it ( 'should parse backoff with minutes and seconds, including fraction of second' , ( ) => {
939- assert . strictEqual (
940- 62500 ,
941- parseBackoffDuration ( 'action throttled, backoff for 1m2.5s' )
942- ) ;
943- } ) ;
944- it ( 'should parse backoff with hours and seconds' , ( ) => {
945- assert . strictEqual (
946- 3602500 ,
947- parseBackoffDuration ( 'action throttled, backoff for 1h2.5s' )
948- ) ;
949- } ) ;
950- it ( 'should parse backoff with hours, minutes, and seconds' , ( ) => {
951- assert . strictEqual (
952- 3662500 ,
953- parseBackoffDuration ( 'action throttled, backoff for 1h1m2.5s' )
954- ) ;
955- } ) ;
956- it ( 'should parse return undefined for unexpected backoff time string format' , ( ) => {
957- assert . strictEqual (
958- undefined ,
959- parseBackoffDuration ( 'action throttled, backoff for 1m2+s' )
960- ) ;
961- } ) ;
962- it ( 'should parse return undefined for unexpected string format' , ( ) => {
963- assert . strictEqual ( undefined , parseBackoffDuration ( 'time 1m2s' ) ) ;
964- } ) ;
965- } ) ;
966917} ) ;
0 commit comments