-
Notifications
You must be signed in to change notification settings - Fork 0
Added regression guard for XSD schema caching #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HassanAkbar
wants to merge
4
commits into
main
Choose a base branch
from
feat/perf-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
60ef7ee
guard xsd schema memoization
HassanAkbar 914dcee
stop retaining xsd documents in build counter
HassanAkbar 4884e63
Merge remote-tracking branch 'origin/main' into feat/perf-spec
HassanAkbar 113a7d7
Assert cache reuse by build count not key shape
HassanAkbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| # Regression guard for the schema memoization in `Dcc::Validate::Xsd`. | ||
| # | ||
| # Asserts no timing on purpose — a wall-clock benchmark would be | ||
| # machine-dependent and flaky in CI. What these examples establish is that one | ||
| # `Nokogiri::XML::Schema` gets built per distinct version, that a lookup returns | ||
| # the schema stored under the version it asked for, and that looking the same | ||
| # version up again — explicitly or via `:auto` — neither rebuilds it nor adds a | ||
| # cache entry. | ||
| RSpec.describe Dcc::Validate::Xsd do | ||
| let(:xml) { File.read(fixtures_path("dcclib", "valid.xml")) } | ||
| let(:cache) { described_class::SCHEMA_CACHE } | ||
| let(:builds) { [] } | ||
|
|
||
| # Records every real schema construction, letting each one through. | ||
| def track_builds | ||
| allow(Nokogiri::XML::Schema) | ||
| .to receive(:new).and_wrap_original do |original, *args| | ||
| builds << args.first | ||
| original.call(*args) | ||
| end | ||
| end | ||
|
|
||
| # `SCHEMA_CACHE` is process-wide. Start cold, then hand the suite back | ||
| # exactly the entries it had. | ||
| around do |example| | ||
| warm = cache.dup | ||
| cache.clear | ||
| example.run | ||
| ensure | ||
| cache.replace(warm) | ||
| end | ||
|
|
||
| # The build count and the cache keys are asserted together on purpose. Two | ||
| # builds alone would also match one version built twice; the keys say which | ||
| # two were built. `.with` cannot discriminate here — the argument is the XSD | ||
| # document, not the version. | ||
| it "builds one schema per distinct version" do | ||
| track_builds | ||
|
|
||
| 3.times { described_class.call(xml, version: "3.3.0") } | ||
| 2.times { described_class.call(xml, version: "3.2.0") } | ||
|
|
||
| expect([builds.size, cache.keys]).to eq([2, %w[3.3.0 3.2.0]]) | ||
| end | ||
|
|
||
| it "hands back the schema cached under the requested version" do | ||
| versions = %w[3.3.0 3.2.0] | ||
| versions.each { |version| described_class.call(xml, version: version) } | ||
|
|
||
| looked_up = versions.to_h { |v| [v, described_class.send(:schema_for, v)] } | ||
|
|
||
| expect(looked_up).to eq(versions.to_h { |v| [v, cache.fetch(v)] }) | ||
| end | ||
|
|
||
| # Pins the explicit-version entry point; the example below pins `:auto`. | ||
| it "keeps exactly one entry when the same version is looked up again" do | ||
| described_class.call(xml, version: "3.3.0") | ||
|
|
||
| expect { 3.times { described_class.call(xml, version: "3.3.0") } } | ||
| .not_to change(cache, :keys).from(%w[3.3.0]) | ||
| end | ||
|
|
||
| it "reuses that entry when the version is auto-detected" do | ||
| described_class.call(xml, version: "3.3.0") | ||
|
|
||
| expect { 3.times { described_class.call(xml) } } | ||
| .not_to change(cache, :keys).from(%w[3.3.0]) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.