diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b425f6f03f2..ed7425b466c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: go-version: [1.20.x] - platform: [ubuntu-latest, windows-2019] + platform: [macos-13] runs-on: ${{ matrix.platform }} steps: - name: Checkout code @@ -49,7 +49,7 @@ jobs: strategy: fail-fast: false matrix: - platform: [ubuntu-latest, windows-2019] + platform: [macos-13] runs-on: ${{ matrix.platform }} continue-on-error: true steps: @@ -88,7 +88,7 @@ jobs: fail-fast: false matrix: go-version: [1.21.x] - platform: [ubuntu-latest, windows-2019] + platform: [macos-13] runs-on: ${{ matrix.platform }} steps: - name: Checkout code diff --git a/js/runner_test.go b/js/runner_test.go index ce4b8f78f84..497d2b7bd73 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -13,7 +13,6 @@ import ( "go/build" "io" "io/fs" - stdlog "log" "math/big" "net" "net/http" @@ -21,7 +20,6 @@ import ( "net/url" "os" "strings" - "sync" "testing" "time" @@ -720,59 +718,6 @@ func TestVURunInterrupt(t *testing.T) { } } -func TestVURunInterruptDoesntPanic(t *testing.T) { - t.Parallel() - r1, err := getSimpleRunner(t, "/script.js", ` - exports.default = function() { while(true) {} } - `) - require.NoError(t, err) - require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)})) - - registry := metrics.NewRegistry() - builtinMetrics := metrics.RegisterBuiltinMetrics(registry) - r2, err := NewFromArchive( - &lib.TestPreInitState{ - Logger: testutils.NewLogger(t), - BuiltinMetrics: builtinMetrics, - Registry: registry, - }, r1.MakeArchive()) - require.NoError(t, err) - testdata := map[string]*Runner{"Source": r1, "Archive": r2} - for name, r := range testdata { - r := r - t.Run(name, func(t *testing.T) { - t.Parallel() - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - samples := newDevNullSampleChannel() - defer close(samples) - var wg sync.WaitGroup - - initVU, err := r.newVU(ctx, 1, 1, samples) - require.NoError(t, err) - for i := 0; i < 100; i++ { - wg.Add(1) - newCtx, newCancel := context.WithCancel(ctx) - vu := initVU.Activate(&lib.VUActivationParams{ - RunContext: newCtx, - DeactivateCallback: func(_ lib.InitializedVU) { wg.Done() }, - }) - ch := make(chan struct{}) - go func() { - close(ch) - vuErr := vu.RunOnce() - require.Error(t, vuErr) - assert.Contains(t, vuErr.Error(), "context canceled") - }() - <-ch - time.Sleep(time.Millisecond * 1) // NOTE: increase this in case of problems ;) - newCancel() - wg.Wait() - } - }) - } -} - func TestVUIntegrationGroups(t *testing.T) { t.Parallel() r1, err := getSimpleRunner(t, "/script.js", ` @@ -1699,169 +1644,6 @@ func TestVUIntegrationVUID(t *testing.T) { } } -/* -CA key: ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIDEm8bxihqYfAsWP39o5DpkAksPBw+3rlDHNX+d69oYGoAoGCCqGSM49 -AwEHoUQDQgAEeeuCFQsdraFJr8JaKbAKfjYpZ2U+p3r/OzcmAsjFO8EckmV9uFZs -Gq3JurKi9Z3dDKQcwinHQ1malicbwWhamQ== ------END EC PRIVATE KEY----- -*/ -func TestVUIntegrationClientCerts(t *testing.T) { - t.Parallel() - clientCAPool := x509.NewCertPool() - assert.True(t, clientCAPool.AppendCertsFromPEM( - []byte("-----BEGIN CERTIFICATE-----\n"+ - "MIIBWzCCAQGgAwIBAgIJAIQMBgLi+DV6MAoGCCqGSM49BAMCMBAxDjAMBgNVBAMM\n"+ - "BU15IENBMCAXDTIyMDEyMTEyMjkzNloYDzMwMjEwNTI0MTIyOTM2WjAQMQ4wDAYD\n"+ - "VQQDDAVNeSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHnrghULHa2hSa/C\n"+ - "WimwCn42KWdlPqd6/zs3JgLIxTvBHJJlfbhWbBqtybqyovWd3QykHMIpx0NZmpYn\n"+ - "G8FoWpmjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\n"+ - "DgQWBBSkukBA8lgFvvBJAYKsoSUR+PX71jAKBggqhkjOPQQDAgNIADBFAiEAiFF7\n"+ - "Y54CMNRSBSVMgd4mQgrzJInRH88KpLsQ7VeOAaQCIEa0vaLln9zxIDZQKocml4Db\n"+ - "AEJr8tDzMKIds6sRTBT4\n"+ - "-----END CERTIFICATE-----"), - )) - serverCert, err := tls.X509KeyPair( - []byte("-----BEGIN CERTIFICATE-----\n"+ - "MIIBcTCCARigAwIBAgIJAIP0njRt16gbMAoGCCqGSM49BAMCMBAxDjAMBgNVBAMM\n"+ - "BU15IENBMCAXDTIyMDEyMTE1MTA0OVoYDzMwMjEwNTI0MTUxMDQ5WjAZMRcwFQYD\n"+ - "VQQDDA4xMjcuMC4wLjE6Njk2OTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABH8Y\n"+ - "exy5LI9r+RNwVpf/5ZX86EigMYHp9YOyiUMmfUfvDig+BGhlwjm7Lh2941Gz4amO\n"+ - "lpN2YAkcd0wnNLHkVOmjUDBOMA4GA1UdDwEB/wQEAwIBBjAMBgNVHRMBAf8EAjAA\n"+ - "MB0GA1UdDgQWBBQ9cIYUwwzfzBXPyRGB5tNpAgHWujAPBgNVHREECDAGhwR/AAAB\n"+ - "MAoGCCqGSM49BAMCA0cAMEQCIDjRZlg+jKgI9K99HOM2wS9+URr6R1/FYLZYBtMc\n"+ - "pq3hAiB9NQxNqV459fgN0BpbiLrEvJjquRFoUr9BWsG+hHrHtQ==\n"+ - "-----END CERTIFICATE-----\n"+ - "-----BEGIN CERTIFICATE-----\n"+ - "MIIBWzCCAQGgAwIBAgIJAIQMBgLi+DV6MAoGCCqGSM49BAMCMBAxDjAMBgNVBAMM\n"+ - "BU15IENBMCAXDTIyMDEyMTEyMjkzNloYDzMwMjEwNTI0MTIyOTM2WjAQMQ4wDAYD\n"+ - "VQQDDAVNeSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHnrghULHa2hSa/C\n"+ - "WimwCn42KWdlPqd6/zs3JgLIxTvBHJJlfbhWbBqtybqyovWd3QykHMIpx0NZmpYn\n"+ - "G8FoWpmjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\n"+ - "DgQWBBSkukBA8lgFvvBJAYKsoSUR+PX71jAKBggqhkjOPQQDAgNIADBFAiEAiFF7\n"+ - "Y54CMNRSBSVMgd4mQgrzJInRH88KpLsQ7VeOAaQCIEa0vaLln9zxIDZQKocml4Db\n"+ - "AEJr8tDzMKIds6sRTBT4\n"+ - "-----END CERTIFICATE-----"), - []byte("-----BEGIN EC PRIVATE KEY-----\n"+ - "MHcCAQEEIHNpjs0P9/ejoUYF5Agzf9clHR4PwBsVfZ+JgslfuBg1oAoGCCqGSM49\n"+ - "AwEHoUQDQgAEfxh7HLksj2v5E3BWl//llfzoSKAxgen1g7KJQyZ9R+8OKD4EaGXC\n"+ - "ObsuHb3jUbPhqY6Wk3ZgCRx3TCc0seRU6Q==\n"+ - "-----END EC PRIVATE KEY-----"), - ) - require.NoError(t, err) - - testdata := map[string]struct { - withClientCert bool - withDomains bool - insecureSkipVerify bool - errMsg string - }{ - "WithoutCert": {false, false, true, "remote error: tls:"}, - "WithCert": {true, true, true, ""}, - "VerifyServerCert": {true, false, false, "certificate signed by unknown authority"}, - "WithoutDomains": {true, false, true, ""}, - } - - listener, err := tls.Listen("tcp", "127.0.0.1:0", &tls.Config{ //nolint:gosec - Certificates: []tls.Certificate{serverCert}, - ClientAuth: tls.RequireAndVerifyClientCert, - ClientCAs: clientCAPool, - }) - require.NoError(t, err) - srv := &http.Server{ //nolint:gosec - Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - _, _ = fmt.Fprintf(w, "ok") - }), - ErrorLog: stdlog.New(io.Discard, "", 0), - } - go func() { _ = srv.Serve(listener) }() - t.Cleanup(func() { _ = listener.Close() }) - for name, data := range testdata { - data := data - - registry := metrics.NewRegistry() - builtinMetrics := metrics.RegisterBuiltinMetrics(registry) - t.Run(name, func(t *testing.T) { - t.Parallel() - - r1, err := getSimpleRunner(t, "/script.js", fmt.Sprintf(` - var http = require("k6/http"); - var k6 = require("k6"); - var check = k6.check; - exports.default = function() { - const res = http.get("https://%s") - check(res, { - 'is status 200': (r) => r.status === 200, - 'verify resp': (r) => r.body.includes('ok'), - }) - }`, listener.Addr().String())) - require.NoError(t, err) - - opt := lib.Options{Throw: null.BoolFrom(true)} - if data.insecureSkipVerify { - opt.InsecureSkipTLSVerify = null.BoolFrom(true) - } - if data.withClientCert { - opt.TLSAuth = []*lib.TLSAuth{ - { - TLSAuthFields: lib.TLSAuthFields{ - Cert: "-----BEGIN CERTIFICATE-----\n" + - "MIIBVzCB/6ADAgECAgkAg/SeNG3XqB0wCgYIKoZIzj0EAwIwEDEOMAwGA1UEAwwF\n" + - "TXkgQ0EwIBcNMjIwMTIxMTUxMjM0WhgPMzAyMTA1MjQxNTEyMzRaMBExDzANBgNV\n" + - "BAMMBmNsaWVudDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKM7OJQMYG4KLtDA\n" + - "gZ8zOg2PimHMmQnjD2HtI4cSwIUJJnvHWLowbFe9fk6XeP9b3dK1ImUI++/EZdVr\n" + - "ABAcngejPzA9MA4GA1UdDwEB/wQEAwIBBjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQW\n" + - "BBSttJe1mcPEnBOZ6wvKPG4zL0m1CzAKBggqhkjOPQQDAgNHADBEAiBPSLgKA/r9\n" + - "u/FW6W+oy6Odm1kdNMGCI472iTn545GwJgIgb3UQPOUTOj0IN4JLJYfmYyXviqsy\n" + - "zk9eWNHFXDA9U6U=\n" + - "-----END CERTIFICATE-----", - Key: "-----BEGIN EC PRIVATE KEY-----\n" + - "MHcCAQEEINDaMGkOT3thu1A0LfLJr3Jd011/aEG6OArmEQaujwgpoAoGCCqGSM49\n" + - "AwEHoUQDQgAEozs4lAxgbgou0MCBnzM6DY+KYcyZCeMPYe0jhxLAhQkme8dYujBs\n" + - "V71+Tpd4/1vd0rUiZQj778Rl1WsAEByeBw==\n" + - "-----END EC PRIVATE KEY-----", - }, - }, - } - if data.withDomains { - opt.TLSAuth[0].TLSAuthFields.Domains = []string{"127.0.0.1"} - } - _, _ = opt.TLSAuth[0].Certificate() - } - require.NoError(t, r1.SetOptions(opt)) - r2, err := NewFromArchive( - &lib.TestPreInitState{ - Logger: testutils.NewLogger(t), - BuiltinMetrics: builtinMetrics, - Registry: registry, - }, r1.MakeArchive()) - require.NoError(t, err) - - runners := map[string]*Runner{"Source": r1, "Archive": r2} - for name, r := range runners { - r := r - t.Run(name, func(t *testing.T) { - t.Parallel() - r.preInitState.Logger, _ = logtest.NewNullLogger() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - initVU, err := r.NewVU(ctx, 1, 1, make(chan metrics.SampleContainer, 100)) - require.NoError(t, err) - vu := initVU.Activate(&lib.VUActivationParams{RunContext: ctx}) - err = vu.RunOnce() - if len(data.errMsg) > 0 { - require.Error(t, err) - assert.ErrorContains(t, err, data.errMsg) - } else { - require.NoError(t, err) - } - }) - } - }) - } -} - func TestHTTPRequestInInitContext(t *testing.T) { t.Parallel() tb := httpmultibin.NewHTTPMultiBin(t)