This repository was archived by the owner on Aug 18, 2026. It is now read-only.
Repository navigation
Add unit tests to increase coverage and fix race condition in GameServersQueue - #505
Merged
Dimitris Gkanatsios (dgkanatsios) merged 7 commits intoMar 24, 2026
Conversation
Add testify-based unit tests in nodeagentmanager_unit_test.go covering: - heartbeatHandler: non-existent GS, logEveryHeartbeat, ignoreHealthFromHeartbeat, Active+StandingBy=>Active operation, Active+Active=>Continue - updateHealthAndStateIfNeeded: no-change, valid transitions, invalid transitions, Active recovery after NodeAgent crash - updateConnectedPlayersIfNeeded: not-active skip, same-count skip, count changes, zero players - gameServerCreatedOrUpdated: new server, non-active skip, Active+Healthy session details, existing server update - gameServerDeleted: removal, non-existent no-op, DeletedFinalStateUnknown wrapping - HeartbeatTimeChecker: recent heartbeat, already-unhealthy, already-marked Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add 5 new test functions covering previously untested code paths: - TestCreateGsdkFolders: tests server log directory creation - TestParseBuildMetadataMultipleSeparators: edge cases with separators - TestParsePortsMultiplePorts: tests with 3+ ports - TestCreateFolderIfNotExistsNestedPath: verifies os.Mkdir behavior - TestGsdkConfigJsonStructure: validates JSON serialization keys Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- latencyserver: TestCreateServerInvalidPort, TestGetResponseEdgeCases (table-driven via DescribeTable), TestServerLoopValidMessage - standby-forecaster: TestGetLinearRegressionPredictionDecreasing, TestGetForecastedServerCountIncreasing, TestLoadConfigK8sSettings, TestLoadConfigMetricConversion, TestConfigRegisterFlagsK8sOverrides Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add new test cases for: - IsNodeReadyAndSchedulable (5 cases: ready/schedulable, unschedulable, no ready condition, ready=false, multiple conditions) - randString (correct length, character set validation) - getValueByState (empty, initializing, standingBy, active, crashed) - ByState sort interface (ordering verification) - NewPodForGameServer (Linux, Windows, annotations/labels preserved) - NewGameServerForGameServerBuild (labels, ownerRef, hostPorts) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com> Agent-Logs-Url: https://github.com/PlayFab/thundernetes/sessions/9b87433c-2cb0-4781-9f8c-c4736f12767b
Dimitris Gkanatsios (dgkanatsios)
approved these changes
Mar 24, 2026
Dimitris Gkanatsios (dgkanatsios)
marked this pull request as ready for review
March 24, 2026 03:13
Dimitris Gkanatsios (dgkanatsios)
approved these changes
Mar 24, 2026
Collaborator
|
Copilot unit tests failed |
Copilot started work on behalf of
Dimitris Gkanatsios (dgkanatsios)
March 24, 2026 03:18
View session
The previous implementation used a read-lock to check existence, released it, then acquired a write-lock. Between these operations a concurrent PopFromQueue could delete the build entry, causing items to be lost. Fix: hold a single write-lock for the entire PushToQueue operation. Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com> Agent-Logs-Url: https://github.com/PlayFab/thundernetes/sessions/53b53407-f735-4dbd-844c-6a664eb45be9
Contributor
Author
The failing test ( Fixed in |
Copilot
AI
changed the title
Add unit tests to increase coverage across all packages
Add unit tests to increase coverage and fix race condition in GameServersQueue
Mar 24, 2026
Dimitris Gkanatsios (dgkanatsios)
approved these changes
Mar 24, 2026
Dimitris Gkanatsios (dgkanatsios)
deleted the
copilot/add-unit-tests-for-coverage
branch
March 24, 2026 03:42
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
53 new unit tests across 5 packages, targeting the largest coverage gaps.
cmd/nodeagent— 22 tests (new file:nodeagentmanager_unit_test.go)heartbeatHandler: non-existent GS, logEveryHeartbeat, ignoreHealthFromHeartbeat, Active/StandingBy operation responsesupdateHealthAndStateIfNeeded: no-op on unchanged state, valid/invalid transitions, crash recovery (empty→Active)updateConnectedPlayersIfNeeded: skip when not Active, skip when count unchanged, count changes, zero playersgameServerCreatedOrUpdated: new server added to map, non-Active skip, Active+Healthy session details propagationgameServerDeleted: map removal, no-op for missing server,DeletedFinalStateUnknownhandlingHeartbeatTimeChecker: recent heartbeat no-mark, already-unhealthy no-mark, no double-markcmd/initcontainer— 5 testscreateGsdkFolders(create + idempotent), multi-port parsing, nested path failure,GsdkConfigJSON key validationcmd/latencyserver— 3 test specscreateServerwith port 0,getResponseedge cases viaDescribeTable,serverLoopend-to-endcmd/standby-forecaster— 5 testspkg/operator/controllers— 18 testsIsNodeReadyAndSchedulable: ready, unschedulable, no condition, Ready=False, multiple conditionsrandString: length and character setgetValueByState: all state→int mappingsByState: sort ordering verificationNewPodForGameServer: Linux, Windows, label/annotation preservationNewGameServerForGameServerBuild: labels, ownerRef, hostPort assignmentBug fix: race condition in
GameServersQueue.PushToQueueFixed a pre-existing race condition in
PushToQueuethat caused the "should work with multiple simultaneous requests" test to be flaky. The old code used a read-lock to check if a build's queue existed, released it, then acquired a write-lock — a concurrentPopFromQueuecould delete the build entry in between, causing items to be lost. Fixed by holding a single write-lock for the entire operation.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.