Skip to content

Add unit tests for Server Subscription and Session handling - #3639

Merged
marcschier merged 7 commits into
masterfrom
copilot/add-test-coverage-for-subscription-session
Mar 31, 2026
Merged

marcschier merged 7 commits into
masterfrom
copilot/add-test-coverage-for-subscription-session

Conversation

Copilot AI commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

No unit tests existed for core Subscription and Session lifecycle logic in Opc.Ua.Server. This adds 75 new tests covering previously untested code paths, compatible with all target frameworks including .NET Framework 4.7.2.

Proposed changes

SubscriptionLifecycleTests.cs — 46 tests:

  • Constructor: null guard validation, initial diagnostics state, IsDurable default
  • Modify: publishing interval, keepalive/lifetime counts, priority, ModifyCount tracking
  • SetPublishingMode: enable/disable with counter tracking, no-op on unchanged state
  • QueueOverflowHandler: MonitoringQueueOverflowCount increments
  • SessionClosed: clears session reference, resets SessionId and diagnostics
  • PublishTimeout: returns BadTimeout StatusChangeNotification, marks subscription expired
  • SubscriptionTransferred: returns GoodSubscriptionTransferred notification
  • SetSubscriptionDurable: BadNotSupported without factory; sets IsDurable=true with support
  • Acknowledge / Republish: sequence number validation, cache hit/miss, message counters
  • Publish: keepalive for new subscription, PublishRequestCount, null context guard, post-timeout null return
  • SetTriggering: invalid item ID and null context guards

SessionExtendedTests.cs — 29 tests:

  • HasExpired, IsSecureChannelValid, Activated state
  • UpdateLocaleIds: change detection, PreferredLocales update, empty array handling
  • SaveContinuationPoint / RestoreContinuationPoint: round-trip, unknown ID, short byte string, remove-on-restore
  • SaveHistoryContinuationPoint / RestoreHistoryContinuationPoint: same patterns
  • ValidateRequest: wrong channel → BadSecureChannelIdInvalid, null header guard, per-service diagnostic counters
  • SessionDiagnostics: name match, positive timeout value

Related Issues

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

Tests follow existing project conventions: NUnit Assert.That constraint syntax, PascalCase method names, ServerFixture-based integration tests for session scenarios, and direct construction with mocks for subscription unit tests. All #region/#endregion directives have been omitted in line with project code style. Mock setup uses default(ValueTask) instead of ValueTask.CompletedTask to ensure compatibility with .NET Framework 4.7.2 and all other target frameworks.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ling

- SubscriptionLifecycleTests.cs: 46 tests covering subscription lifecycle
  (constructor, modify, publish mode, queue overflow, session closed,
  publish timeout, republish, durable subscriptions, triggering, etc.)
- SessionExtendedTests.cs: 29 tests covering session operations
  (expiry, channel validation, locale updates, continuation points,
  diagnostics, ValidateRequest, etc.)

All 578 tests pass (503 existing + 75 new).

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OPCFoundation/UA-.NETStandard/sessions/d28cf5ce-a461-4e95-b23f-689ec5f5113b
@CLAassistant

CLAassistant commented Mar 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ romanett
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@marcschier

Copy link
Copy Markdown
Collaborator

@copilot remove all #region / #endregion directives from the new code.

Copilot AI commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot remove all #region / #endregion directives from the new code.

Done in bbb6636 — all #region/#endregion directives have been removed from both SubscriptionLifecycleTests.cs and SessionExtendedTests.cs.

Copilot AI requested a review from marcschier March 27, 2026 07:22
@marcschier
marcschier marked this pull request as ready for review March 27, 2026 07:23
@marcschier

Copy link
Copy Markdown
Collaborator

@copilot ensure build succeeds against .net framework. Current error for the tests: D:\a\1\s\Tests\Opc.Ua.Server.Tests\SubscriptionLifecycleTests.cs(88,59): error CS0117: 'ValueTask' does not contain a definition for 'CompletedTask' [D:\a\1\s\Tests\Opc.Ua.Server.Tests\Opc.Ua.Server.Tests.csproj::TargetFramework=net472]

Copilot AI commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ensure build succeeds against .net framework. Current error for the tests: D:\a\1\s\Tests\Opc.Ua.Server.Tests\SubscriptionLifecycleTests.cs(88,59): error CS0117: 'ValueTas...

Fixed in d8d4454 — replaced ValueTask.CompletedTask (net5+ only) with default(ValueTask), which works across all target frameworks including net472.

@romanett
romanett requested review from marcschier and removed request for marcschier March 30, 2026 15:36
@marcschier
marcschier merged commit f859245 into master Mar 31, 2026
185 of 188 checks passed
@romanett
romanett deleted the copilot/add-test-coverage-for-subscription-session branch April 21, 2026 05:09
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.

4 participants