@@ -12,17 +12,35 @@ import (
1212)
1313
1414type DriverWrapper struct {
15- vu modules.VU
16- lg * zap.Logger
17- drv driver.Driver
18- onceUpdateDialler sync.Once
15+ vu modules.VU
16+ lg * zap.Logger
17+ drv driver.Driver
18+
19+ configureOnce sync.Once
1920}
2021
21- func (d * DriverWrapper ) RunQuery (sql string , args map [string ]any ) any {
22- d .onceUpdateDialler .Do (
23- func () { d .drv .UpdateDialler (d .vu .Context (), d .vu .State ().Dialer .DialContext ) },
22+ // This is a custom "VU setup" hook.
23+ //
24+ // NOTE: k6 have no option to make per VU setup code execution by itself.
25+ // Check https://github.com/grafana/k6/issues/785
26+ // https://github.com/grafana/k6/issues/1638
27+ //
28+ // Unfortunatly it's impossible to pass DialFunc at [Instance.NewDriverByConfigBin]
29+ // because there is nil [modules.VU.State]. It may be fixed in the feature:
30+ // https://github.com/grafana/k6/issues?q=is%3Aopen+is%3Aissue+label%3Anew-http
31+ // https://github.com/grafana/k6/issues/2293
32+ func (d * DriverWrapper ) configure () {
33+ d .configureOnce .Do (
34+ func () {
35+ d .drv .Configure (d .vu .Context (), driver.Options {
36+ DialFunc : d .vu .State ().Dialer .DialContext ,
37+ })
38+ },
2439 )
40+ }
2541
42+ func (d * DriverWrapper ) RunQuery (sql string , args map [string ]any ) any {
43+ d .configure ()
2644 stats , err := d .drv .RunQuery (d .vu .Context (), sql , args )
2745 if err != nil {
2846 return fmt .Errorf ("error while executing sql query: %w" , err )
@@ -31,13 +49,8 @@ func (d *DriverWrapper) RunQuery(sql string, args map[string]any) any {
3149}
3250
3351// InsertValuesBin starts bulk insert blocking operation on driver.
34- func (d * DriverWrapper ) InsertValuesBin (
35- insertMsg []byte ,
36- count int64 ,
37- ) any {
38- d .onceUpdateDialler .Do (
39- func () { d .drv .UpdateDialler (d .vu .Context (), d .vu .State ().Dialer .DialContext ) },
40- )
52+ func (d * DriverWrapper ) InsertValuesBin (insertMsg []byte , count int64 ) any {
53+ d .configure ()
4154 var descriptor stroppy.InsertDescriptor
4255 err := proto .Unmarshal (insertMsg , & descriptor )
4356 if err != nil {
0 commit comments