11const jmespath = require ( "jmespath" ) ;
2- const { DynamoDB } = require ( "../../../clients/client-dynamodb" ) ;
2+ const { DynamoDB, waitForTableExists , waitForTableNotExists } = require ( "../../../clients/client-dynamodb" ) ;
33
4- /**
5- * Waits for the tableExists state by periodically calling the underlying
6- * DynamoDB.describeTable() operation every 5 seconds (at most 25 times).
7- */
8- function waitForTableExists ( world , callback ) {
9- const params = {
10- TableName : world . tableName ,
11- } ;
12-
13- const maxAttempts = 25 ;
14- const delay = 5000 ;
15- let currentAttempt = 0 ;
16-
17- const checkForTableExists = ( ) => {
18- currentAttempt ++ ;
19- world . service . describeTable ( params , function ( err , data ) {
20- if ( currentAttempt > maxAttempts ) {
21- callback ( new Error ( "waitForTableExists: max attempts exceeded" ) ) ;
22- } else if ( data && data . Table && data . Table . TableStatus === "ACTIVE" ) {
23- callback ( ) ;
24- } else {
25- setTimeout ( function ( ) {
26- checkForTableExists ( ) ;
27- } , delay ) ;
28- }
29- } ) ;
30- } ;
31- checkForTableExists ( ) ;
4+ function waitForTableExistsCallback ( world , callback ) {
5+ waitForTableExists ( { client : world . service } , { TableName : world . tableName } ) . then (
6+ function ( data ) {
7+ callback ( ) ;
8+ } ,
9+ function ( err ) {
10+ callback ( err ) ;
11+ }
12+ ) ;
3213}
3314
34- /**
35- * Waits for the tableNotExists state by periodically calling the underlying
36- * DynamoDB.describeTable() operation every 5 seconds (at most 25 times).
37- */
38- function waitForTableNotExists ( world , callback ) {
39- const params = {
40- TableName : world . tableName ,
41- } ;
42-
43- const maxAttempts = 25 ;
44- const delay = 5000 ;
45- let currentAttempt = 0 ;
46-
47- const checkForTableNotExists = ( ) => {
48- currentAttempt ++ ;
49- world . service . describeTable ( params , function ( err , data ) {
50- if ( currentAttempt > maxAttempts ) {
51- callback ( new Error ( "waitForTableNotExists: max attempts exceeded" ) ) ;
52- } else if ( err && err . name === "ResourceNotFoundException" ) {
53- callback ( ) ;
54- } else {
55- setTimeout ( function ( ) {
56- checkForTableNotExists ( ) ;
57- } , delay ) ;
58- }
59- } ) ;
60- } ;
61- checkForTableNotExists ( ) ;
15+ function waitForTableNotExistsWithCallback ( world , callback ) {
16+ waitForTableNotExists ( { client : world . service } , { TableName : world . tableName } ) . then (
17+ function ( data ) {
18+ callback ( ) ;
19+ } ,
20+ function ( err ) {
21+ callback ( err ) ;
22+ }
23+ ) ;
6224}
25+
6326const { Before, Given, Then, When } = require ( "cucumber" ) ;
6427
6528Before ( { tags : "@dynamodb" } , function ( scenario , next ) {
@@ -82,7 +45,7 @@ function createTable(world, callback) {
8245 callback ( err ) ;
8346 return ;
8447 }
85- waitForTableExists ( world , callback ) ;
48+ waitForTableExistsCallback ( world , callback ) ;
8649 } ) ;
8750}
8851
@@ -154,11 +117,11 @@ When("I delete the table", function (next) {
154117} ) ;
155118
156119Then ( "the table should eventually exist" , function ( callback ) {
157- waitForTableExists ( this , callback ) ;
120+ waitForTableExistsCallback ( this , callback ) ;
158121} ) ;
159122
160123Then ( "the table should eventually not exist" , function ( callback ) {
161- waitForTableNotExists ( this , callback ) ;
124+ waitForTableNotExistsWithCallback ( this , callback ) ;
162125} ) ;
163126
164127Given ( "my first request is corrupted with CRC checking (ON|OFF)" , function ( toggle , callback ) {
0 commit comments