|
| 1 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +# Stress test: fetch real packages from all 10 registries |
| 3 | +# Run: mix run test/stress_test.exs |
| 4 | + |
| 5 | +alias Opsm.Registries.Registry |
| 6 | + |
| 7 | +# Test packages per registry — well-known, stable packages |
| 8 | +test_packages = [ |
| 9 | + # npm (10 packages) |
| 10 | + {:npm, "express", "4.18.2"}, |
| 11 | + {:npm, "lodash", "latest"}, |
| 12 | + {:npm, "chalk", "5.3.0"}, |
| 13 | + {:npm, "axios", "latest"}, |
| 14 | + {:npm, "uuid", "latest"}, |
| 15 | + {:npm, "debug", "latest"}, |
| 16 | + {:npm, "commander", "latest"}, |
| 17 | + {:npm, "minimist", "latest"}, |
| 18 | + {:npm, "glob", "latest"}, |
| 19 | + {:npm, "semver", "latest"}, |
| 20 | + |
| 21 | + # Hex/Elixir (10 packages) |
| 22 | + {:hex, "jason", "latest"}, |
| 23 | + {:hex, "plug", "latest"}, |
| 24 | + {:hex, "phoenix", "latest"}, |
| 25 | + {:hex, "ecto", "latest"}, |
| 26 | + {:hex, "telemetry", "latest"}, |
| 27 | + {:hex, "nimble_parsec", "latest"}, |
| 28 | + {:hex, "ex_doc", "latest"}, |
| 29 | + {:hex, "earmark_parser", "latest"}, |
| 30 | + {:hex, "decimal", "latest"}, |
| 31 | + {:hex, "mime", "latest"}, |
| 32 | + |
| 33 | + # Cargo/Crates (10 packages) |
| 34 | + {:cargo, "serde", "latest"}, |
| 35 | + {:cargo, "tokio", "latest"}, |
| 36 | + {:cargo, "rand", "latest"}, |
| 37 | + {:cargo, "clap", "latest"}, |
| 38 | + {:cargo, "regex", "latest"}, |
| 39 | + {:cargo, "log", "latest"}, |
| 40 | + {:cargo, "anyhow", "latest"}, |
| 41 | + {:cargo, "thiserror", "latest"}, |
| 42 | + {:cargo, "chrono", "latest"}, |
| 43 | + {:cargo, "reqwest", "latest"}, |
| 44 | + |
| 45 | + # PyPI (10 packages) |
| 46 | + {:pypi, "requests", "latest"}, |
| 47 | + {:pypi, "flask", "latest"}, |
| 48 | + {:pypi, "numpy", "latest"}, |
| 49 | + {:pypi, "pytest", "latest"}, |
| 50 | + {:pypi, "click", "latest"}, |
| 51 | + {:pypi, "pyyaml", "latest"}, |
| 52 | + {:pypi, "six", "latest"}, |
| 53 | + {:pypi, "packaging", "latest"}, |
| 54 | + {:pypi, "idna", "latest"}, |
| 55 | + {:pypi, "certifi", "latest"}, |
| 56 | + |
| 57 | + # RubyGems (10 packages) |
| 58 | + {:gem, "rails", "latest"}, |
| 59 | + {:gem, "rake", "latest"}, |
| 60 | + {:gem, "bundler", "latest"}, |
| 61 | + {:gem, "rspec", "latest"}, |
| 62 | + {:gem, "nokogiri", "latest"}, |
| 63 | + {:gem, "sinatra", "latest"}, |
| 64 | + {:gem, "puma", "latest"}, |
| 65 | + {:gem, "redis", "latest"}, |
| 66 | + {:gem, "json", "latest"}, |
| 67 | + {:gem, "minitest", "latest"}, |
| 68 | + |
| 69 | + # Go Modules (10 packages) |
| 70 | + {:go, "github.com/gin-gonic/gin", "latest"}, |
| 71 | + {:go, "github.com/fatih/color", "latest"}, |
| 72 | + {:go, "github.com/spf13/cobra", "latest"}, |
| 73 | + {:go, "github.com/spf13/viper", "latest"}, |
| 74 | + {:go, "github.com/stretchr/testify", "latest"}, |
| 75 | + {:go, "github.com/sirupsen/logrus", "latest"}, |
| 76 | + {:go, "github.com/gorilla/mux", "latest"}, |
| 77 | + {:go, "golang.org/x/text", "latest"}, |
| 78 | + {:go, "golang.org/x/net", "latest"}, |
| 79 | + {:go, "golang.org/x/sync", "latest"}, |
| 80 | + |
| 81 | + # Pub.dev/Dart (10 packages) |
| 82 | + {:pub, "http", "latest"}, |
| 83 | + {:pub, "path", "latest"}, |
| 84 | + {:pub, "json_annotation", "latest"}, |
| 85 | + {:pub, "provider", "latest"}, |
| 86 | + {:pub, "intl", "latest"}, |
| 87 | + {:pub, "collection", "latest"}, |
| 88 | + {:pub, "meta", "latest"}, |
| 89 | + {:pub, "args", "latest"}, |
| 90 | + {:pub, "crypto", "latest"}, |
| 91 | + {:pub, "async", "latest"}, |
| 92 | + |
| 93 | + # Hackage/Haskell (10 packages) |
| 94 | + {:hackage, "aeson", "latest"}, |
| 95 | + {:hackage, "text", "latest"}, |
| 96 | + {:hackage, "bytestring", "latest"}, |
| 97 | + {:hackage, "containers", "latest"}, |
| 98 | + {:hackage, "mtl", "latest"}, |
| 99 | + {:hackage, "transformers", "latest"}, |
| 100 | + {:hackage, "parsec", "latest"}, |
| 101 | + {:hackage, "vector", "latest"}, |
| 102 | + {:hackage, "lens", "latest"}, |
| 103 | + {:hackage, "attoparsec", "latest"}, |
| 104 | + |
| 105 | + # NuGet/.NET (10 packages) |
| 106 | + {:nuget, "Newtonsoft.Json", "latest"}, |
| 107 | + {:nuget, "Serilog", "latest"}, |
| 108 | + {:nuget, "AutoMapper", "latest"}, |
| 109 | + {:nuget, "Dapper", "latest"}, |
| 110 | + {:nuget, "FluentValidation", "latest"}, |
| 111 | + {:nuget, "Moq", "latest"}, |
| 112 | + {:nuget, "xunit", "latest"}, |
| 113 | + {:nuget, "Polly", "latest"}, |
| 114 | + {:nuget, "MediatR", "latest"}, |
| 115 | + {:nuget, "Swashbuckle.AspNetCore", "latest"}, |
| 116 | + |
| 117 | + # Maven/Java (10 packages) |
| 118 | + {:maven, "com.google.guava:guava", "latest"}, |
| 119 | + {:maven, "org.slf4j:slf4j-api", "latest"}, |
| 120 | + {:maven, "junit:junit", "latest"}, |
| 121 | + {:maven, "com.fasterxml.jackson.core:jackson-databind", "latest"}, |
| 122 | + {:maven, "org.apache.commons:commons-lang3", "latest"}, |
| 123 | + {:maven, "commons-io:commons-io", "latest"}, |
| 124 | + {:maven, "org.projectlombok:lombok", "latest"}, |
| 125 | + {:maven, "com.google.code.gson:gson", "latest"}, |
| 126 | + {:maven, "org.mockito:mockito-core", "latest"}, |
| 127 | + {:maven, "ch.qos.logback:logback-classic", "latest"}, |
| 128 | +] |
| 129 | + |
| 130 | +IO.puts("=" |> String.duplicate(70)) |
| 131 | +IO.puts("OPSM Stress Test: #{length(test_packages)} packages across 10 registries") |
| 132 | +IO.puts("=" |> String.duplicate(70)) |
| 133 | +IO.puts("") |
| 134 | + |
| 135 | +# Group by registry |
| 136 | +grouped = Enum.group_by(test_packages, fn {forth, _, _} -> forth end) |
| 137 | + |
| 138 | +results = %{ok: 0, error: 0, total: length(test_packages)} |
| 139 | +errors = [] |
| 140 | + |
| 141 | +{results, errors} = |
| 142 | + Enum.reduce(grouped, {results, errors}, fn {forth, packages}, {res_acc, err_acc} -> |
| 143 | + IO.puts("--- @#{forth} (#{length(packages)} packages) ---") |
| 144 | + |
| 145 | + {res, errs} = |
| 146 | + Enum.reduce(packages, {res_acc, err_acc}, fn {_forth, name, version}, {r, e} -> |
| 147 | + start = System.monotonic_time(:millisecond) |
| 148 | + |
| 149 | + case Registry.fetch(forth, name, version) do |
| 150 | + {:ok, pkg} -> |
| 151 | + elapsed = System.monotonic_time(:millisecond) - start |
| 152 | + checksum_status = if pkg.checksum, do: "✓ #{pkg.checksum_algo}", else: "✗ none" |
| 153 | + dep_count = map_size(pkg.manifest.dependencies || %{}) |
| 154 | + IO.puts(" ✓ #{name}@#{pkg.version} (#{elapsed}ms, deps: #{dep_count}, checksum: #{checksum_status})") |
| 155 | + {%{r | ok: r.ok + 1}, e} |
| 156 | + |
| 157 | + {:error, reason} -> |
| 158 | + elapsed = System.monotonic_time(:millisecond) - start |
| 159 | + IO.puts(" ✗ #{name} FAILED (#{elapsed}ms): #{inspect(reason)}") |
| 160 | + {%{r | error: r.error + 1}, [{forth, name, reason} | e]} |
| 161 | + end |
| 162 | + end) |
| 163 | + |
| 164 | + IO.puts("") |
| 165 | + {res, errs} |
| 166 | + end) |
| 167 | + |
| 168 | +IO.puts("=" |> String.duplicate(70)) |
| 169 | +IO.puts("RESULTS: #{results.ok}/#{results.total} succeeded, #{results.error} failed") |
| 170 | +IO.puts("=" |> String.duplicate(70)) |
| 171 | + |
| 172 | +if errors != [] do |
| 173 | + IO.puts("") |
| 174 | + IO.puts("FAILURES:") |
| 175 | + for {forth, name, reason} <- Enum.reverse(errors) do |
| 176 | + IO.puts(" @#{forth}/#{name}: #{inspect(reason)}") |
| 177 | + end |
| 178 | +end |
| 179 | + |
| 180 | +# Exit with appropriate code |
| 181 | +if results.error > 0 do |
| 182 | + IO.puts("\n⚠ #{results.error} package(s) failed to resolve") |
| 183 | +else |
| 184 | + IO.puts("\n✓ All #{results.total} packages resolved successfully!") |
| 185 | +end |
0 commit comments