Skip to content
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

Deterministic ordering of properties #1396

Closed
carl-berg opened this issue Feb 6, 2025 · 3 comments
Closed

Deterministic ordering of properties #1396

carl-berg opened this issue Feb 6, 2025 · 3 comments

Comments

@carl-berg
Copy link

The problem

While using Verify to verify objects that are loaded by NHibernate ORM (which by default uses lazy loading), the ordering of properties does not seem to be deterministic, but rather seem to depend on which objects are already loaded in cache and which are not. This can cause a lot of head scratching when something can seem to work the same way on a developer's machine, but not the same on the build server where properties may come in different order.

Possible workarounds

A possible work around is to make sure entities are loaded before handing them off to Verify which is a bit cumbersome, but a possible solution.
Another work around is to globally set VerifierSettings.SortPropertiesAlphabetically(); which will affect all tests (as far as i can understand)?

Question

Is there another solution to this problem than my potential workarounds?

@SimonCropp
Copy link
Member

the serialization of classes should be consitent. that uses reflection. so what types are u verifying?

yes SortPropertiesAlphabetically is global

can u share a repro?

@carl-berg
Copy link
Author

I'm trying to create a stand alone repo, but can't seem to easily reproduce the behavior. I suspect the problem maybe lies in that NHiberate uses proxy objects that maybe does not always return properties in a deterministic way (which, if that is the case, then this is not a Verify issue). In the repo where we're actually experiencing problems, we have a large domain model and usually the problem only shows up when other tests have run first (unclear why that is).... but i will try to extend my smaller repo with more tests and see if i can get the problem to show up more reliably.

@carl-berg
Copy link
Author

I asked the same question at the NHibernate repo and it seems likely that it's an issue with the NHibernate dynamic proxies used for lazy loading. I will try to get more answers about possible work arounds there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants