@@ -53,51 +53,43 @@ const redisClient = new redis.Client({
53
53
// in the context of the measureUsingRedisData function.
54
54
const crocodileIDs = new Array (0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );
55
55
56
- export function measureRedisPerformance () {
56
+ export async function measureRedisPerformance () {
57
57
// VUs are executed in a parallel fashion,
58
58
// thus, to ensure that parallel VUs are not
59
59
// modifying the same key at the same time,
60
60
// we use keys indexed by the VU id.
61
61
const key = ` foo-${ exec .vu .idInTest } ` ;
62
62
63
- redisClient
64
- .set (` foo-${ exec .vu .idInTest } ` , 1 )
65
- .then (() => redisClient .get (` foo-${ exec .vu .idInTest } ` ))
66
- .then ((value ) => redisClient .incrBy (` foo-${ exec .vu .idInTest } ` , value))
67
- .then ((_ ) => redisClient .del (` foo-${ exec .vu .idInTest } ` ))
68
- .then ((_ ) => redisClient .exists (` foo-${ exec .vu .idInTest } ` ))
69
- .then ((exists ) => {
70
- if (exists !== 0 ) {
71
- throw new Error (' foo should have been deleted' );
72
- }
73
- });
63
+ await redisClient .set (key, 1 );
64
+ await redisClient .incrBy (key, 10 );
65
+ if (await redisClient .get (key) !== ' 11' ) {
66
+ throw new Error (' foo should have been incremented to 11' );
67
+ }
68
+
69
+ await redisClient .del (key);
70
+ if (await redisClient .exists (key) !== 0 ) {
71
+ throw new Error (' foo should have been deleted' );
72
+ }
74
73
}
75
74
76
- export function setup () {
77
- redisClient .sadd (' crocodile_ids' , ... crocodileIDs);
75
+ export async function setup () {
76
+ await redisClient .sadd (' crocodile_ids' , ... crocodileIDs);
78
77
}
79
78
80
- export function measureUsingRedisData () {
79
+ export async function measureUsingRedisData () {
81
80
// Pick a random crocodile id from the dedicated redis set,
82
81
// we have filled in setup().
83
- redisClient
84
- .srandmember (' crocodile_ids' )
85
- .then ((randomID ) => {
86
- const url = ` https://test-api.k6.io/public/crocodiles/${ randomID} ` ;
87
- const res = http .get (url);
88
-
89
- check (res, {
90
- ' status is 200 ' : (r ) => r .status === 200 ,
91
- ' content-type is application/json ' : (r ) => r .headers [' content-type' ] === ' application/json' ,
92
- });
93
-
94
- return url;
95
- })
96
- .then ((url ) => redisClient .hincrby (' k6_crocodile_fetched' , url, 1 ));
82
+ const randomID = await redisClient .srandmember (' crocodile_ids' );
83
+ const url = ` https://test-api.k6.io/public/crocodiles/${ randomID} ` ;
84
+ const res = http .get (url);
85
+
86
+ check (res, {' status is 200 ' : (r ) => r .status === 200 });
87
+
88
+ await redisClient .hincrby (' k6_crocodile_fetched' , url, 1 );
97
89
}
98
90
99
- export function teardown () {
100
- redisClient .del (' crocodile_ids' );
91
+ export async function teardown () {
92
+ await redisClient .del (' crocodile_ids' );
101
93
}
102
94
103
95
export function handleSummary (data ) {
0 commit comments