Added regression guard for XSD schema caching - #15
Draft
HassanAkbar wants to merge 4 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a dedicated regression spec to guard Dcc::Validate::Xsd schema memoization behavior, replacing a prior example that didn’t meaningfully constrain caching correctness.
Changes:
- Add
spec/dcc/validate/xsd_performance_spec.rbwith four examples asserting per-version schema caching and reuse (including:auto). - Remove the previous “caches the loaded schema” example from
spec/dcc/validate_spec.rb.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/dcc/validate/xsd_performance_spec.rb | New regression coverage for XSD schema cache behavior (build count, keying, reuse, :auto). |
| spec/dcc/validate_spec.rb | Removes an ineffective cache assertion in favor of the dedicated regression guard. |
Suppressed comments (2)
spec/dcc/validate/xsd_performance_spec.rb:56
equses==, which may not guarantee object identity. Since this example is intended to guard memoization, it should assert thatschema_forreturns the exact same object instance stored inSCHEMA_CACHE(viabe/equal).
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)] })
spec/dcc/validate/xsd_performance_spec.rb:47
- This assertion makes the spec order-dependent on
cache.keys(insertion order). The behavior being guarded is “which versions are cached”, not key ordering, so this can be made more robust by asserting count and keys separately.
expect([builds.size, cache.keys]).to eq([2, %w[3.3.0 3.2.0]])
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
spec/dcc/validate/xsd_performance_spec.rb:59
- This example uses
sendto call the privateschema_formethod. The repository contribution guidelines explicitly forbid usingsendto call private methods (see CONTRIBUTING.adoc:34). You can assert the same behavior via the public.callAPI by instrumenting the cached schema instances and checking that each version’s cached schema receives exactly one#validatecall when that version is requested.
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)] }
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds the missing regression spec for XSD schema memoization, and removes an existing example that proved nothing.
The caching already worked. What was missing was anything stopping someone breaking it.
The deleted example asserted the cache "does not grow". Every broken cache also does
not grow, so it passed against no caching at all, a cache that ignores the version key,
and one that reloads on every call.
Four examples, each the sole catcher of a distinct defect:
Known and accepted:
anything is fast.
SCHEMA_CACHEand calls a private method. A cache-behaviour guardhas to touch the cache it guards.
aroundhook snapshots and restores the cache.SCHEMA_CACHE[version] ||= ...is not atomic. That isduplicated work, not corruption, and fixing it means changing
lib/.