Skip to content

test: Add property-based tests for Agones resources#31

Draft
NAME-ASHWANIYADAV wants to merge 3 commits into
agones-dev:mainfrom
NAME-ASHWANIYADAV:test/property-based-tests
Draft

test: Add property-based tests for Agones resources#31
NAME-ASHWANIYADAV wants to merge 3 commits into
agones-dev:mainfrom
NAME-ASHWANIYADAV:test/property-based-tests

Conversation

@NAME-ASHWANIYADAV

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Draft — depends on #30 . Will be marked ready for review after PR #30 merge and this branch is rebased.

Type of change

  • 🐛 Bug fix
  • 🚀 New feature / enhancement
  • 📖 Documentation
  • 🧹 Refactoring / cleanup
  • ⚙️ CI / tooling
  • ⚠️ Breaking change

What this PR does

This PR adds property-based testing to the Agones plugin using the fast-check framework. It verifies invariants across Agones resource models and utilities using randomly generated inputs.

Added 6 new test files (*.property.test.ts):

  • buildAllocationBody: 11 invariants (structural guarantees, namespace propagation, label trimming, mutation filtering)
  • StateChip: 3 invariants (no crash on any string, valid MUI colors, known state mapping fallback)
  • GameServer: 9 invariants (getter return types, port formatting, protocol/policy defaults)
  • Fleet: 3 invariants (numeric types, scheduling/strategy defaults)
  • FleetAutoscaler: 3 invariants (numeric/boolean return types)
  • GameServerAllocation: 2 invariants (string types, port "name:port" format)

Total: 31 property checks generating ~3,100 random test cases per run.

Note: Depends on the testing infrastructure introduced in the previous PR.

Test plan

Automated checks

  • npm ci
  • npm run build
  • npm run tsc
  • npm run lint
  • npm run format -- --check
  • npm run test

All 70 tests (39 existing + 31 new property tests) pass successfully.

Notes for reviewers

One interesting finding during implementation: fast-check generated "__proto__" as a counterexample for the StateChip color lookup test, which broke the STATE_COLORS[state] ?? 'default' logic due to JS prototype pollution behavior. This was fixed in the test by using Object.prototype.hasOwnProperty.call().

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV marked this pull request as draft July 4, 2026 14:19
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the test/property-based-tests branch from 6fdb983 to 9420c51 Compare July 7, 2026 18:09

@markmandel markmandel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only saw one small thing.

function fcGameServerJson(): fc.Arbitrary<any> {
const fcSpecPort = fc.record({
name: fc.option(fc.string({ minLength: 1, maxLength: 15 }), { nil: undefined }),
portPolicy: fc.option(fc.constantFrom('Dynamic', 'Static', 'Passthrough'), { nil: undefined }),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also have "None" as a port value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the fcGameServerJson generator and the assertion to include "None" as a valid portPolicy value. Tests are passing!

Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants