14
14
* limitations under the License.
15
15
*/
16
16
17
+ import { Session , exec } from "@gatling.io/core" ;
18
+
19
+ const session = null as unknown as Session ;
20
+
17
21
//#sessions-are-immutable
18
22
// wrong usage: result from Session#set is discarded
19
23
exec ( ( session ) => {
@@ -28,18 +32,20 @@ exec((session) => {
28
32
} ) ;
29
33
//#sessions-are-immutable
30
34
31
- //#set
32
- // set one single attribute
33
- const newSession1 = session . set ( "key" , "whateverValue" ) ;
34
- // set multiple attributes
35
- const newSession2 = session . setAll ( { "key" : "value" } ) ;
36
- // remove one single attribute
37
- const newSession3 = session . remove ( "key" ) ;
38
- // remove multiple attributes
39
- const newSession4 = session . removeAll ( "key1" , "key2" ) ;
40
- // remove all non Gatling internal attributes
41
- const newSession5 = session . reset ( ) ;
42
- //#set
35
+ const set = ( ) => {
36
+ //#set
37
+ // set one single attribute
38
+ const newSession1 = session . set ( "key" , "whateverValue" ) ;
39
+ // set multiple attributes
40
+ const newSession2 = session . setAll ( { "key" : "value" } ) ;
41
+ // remove one single attribute
42
+ const newSession3 = session . remove ( "key" ) ;
43
+ // remove multiple attributes
44
+ const newSession4 = session . removeAll ( "key1" , "key2" ) ;
45
+ // remove all non Gatling internal attributes
46
+ const newSession5 = session . reset ( ) ;
47
+ //#set
48
+ } ;
43
49
44
50
//#get
45
51
// check if an attribute is stored in the session
@@ -58,13 +64,15 @@ const scenario = session.scenario();
58
64
const groups = session . groups ( ) ;
59
65
//#properties
60
66
61
- //#state
62
- // return true if the virtual user has experienced a failure before this point
63
- const failed = session . isFailed ( ) ;
64
- // reset the state to success
65
- // so that interrupt mechanisms such as exitHereIfFailed don't trigger
66
- const newSession1 = session . markAsSucceeded ( ) ;
67
- // force the state to failure
68
- // so that interrupt mechanisms such as exitHereIfFailed do trigger
69
- const newSession2 = session . markAsFailed ( ) ;
70
- //#state
67
+ const state = ( ) => {
68
+ //#state
69
+ // return true if the virtual user has experienced a failure before this point
70
+ const failed = session . isFailed ( ) ;
71
+ // reset the state to success
72
+ // so that interrupt mechanisms such as exitHereIfFailed don't trigger
73
+ const newSession1 = session . markAsSucceeded ( ) ;
74
+ // force the state to failure
75
+ // so that interrupt mechanisms such as exitHereIfFailed do trigger
76
+ const newSession2 = session . markAsFailed ( ) ;
77
+ //#state
78
+ } ;
0 commit comments