grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
24.93k stars 1.23k forks source link

Allow one pseudo-JS module to access the ModuleInstance of another module #2293

Open na-- opened 2 years ago

na-- commented 2 years ago

(Extracted from https://github.com/grafana/k6/pull/2226, and somewhat connected to https://github.com/grafana/k6/issues/2258 and https://github.com/grafana/k6/issues/1802)

It would be quite nice if one pseudo-JS module is able to access the modules.Instance of another module. For example, if k6/ws is able to access the module instance of k6/http, though ideally any module (regardless of built-in or extension) should be able to access any other module.

This will allow us to move a lot of the (mostly) HTTP-specific cruft from lib.State to a much more appropriate place: https://github.com/grafana/k6/blob/922c963f46466ba89deb506115a23b7bc7d2c822/lib/state.go#L56-L63 But still allow other parts of the codebase (like k6/ws and k6/grpc) to access the default HTTP transport or cookie jar, when they need to.

na-- commented 2 years ago

As a bonus, the lengthy initialization of HTTP-specific things that currently happens during VU init: https://github.com/grafana/k6/blob/922c963f46466ba89deb506115a23b7bc7d2c822/js/runner.go#L157-L224

Would be moved to a much more appropriate place in the k6/http module, e.g. here: https://github.com/grafana/k6/blob/8a475aba3b2f096509f7d0f41752f0a02738f7ef/js/modules/k6/http/http.go#L69-L72