From 36927729a49a2b4703117b5e37ac1a93e49245c7 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 24 Dec 2025 20:24:05 -0500 Subject: [PATCH] test: add scheduler service isolation test for plugin instances Signed-off-by: Deluan --- plugins/host_scheduler_test.go | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/host_scheduler_test.go b/plugins/host_scheduler_test.go index 188167a9d..24ff48c5e 100644 --- a/plugins/host_scheduler_test.go +++ b/plugins/host_scheduler_test.go @@ -232,6 +232,42 @@ var _ = Describe("SchedulerService", Ordered, func() { }) }) + Describe("Scheduler Service Isolation", func() { + It("should share the same scheduler service across multiple plugin instances", func() { + // This test verifies that when we call plugin.create() multiple times + // (creating multiple instances from the same compiled plugin), they all + // share the same scheduler service. This is the expected behavior since + // the scheduler service is registered once per plugin at compile time. + + // Get the plugin instance + manager.mu.RLock() + instance, ok := manager.plugins["fake-scheduler"] + manager.mu.RUnlock() + Expect(ok).To(BeTrue()) + + // Schedule a task using the service directly + _, err := testService.ScheduleOneTime(GinkgoT().Context(), 60, "shared-data", "shared-id") + Expect(err).ToNot(HaveOccurred()) + Expect(testService.GetScheduleCount()).To(Equal(1)) + + // Create a second plugin instance + instance2, err := instance.create() + Expect(err).ToNot(HaveOccurred()) + defer instance2.Close(GinkgoT().Context()) + + // The scheduler service is shared, so the schedule ID should clash + // if another instance tries to use the same ID + _, err = testService.ScheduleOneTime(GinkgoT().Context(), 60, "other-data", "shared-id") + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("already exists")) + + // But different IDs should work fine + _, err = testService.ScheduleOneTime(GinkgoT().Context(), 60, "instance2-data", "instance2-id") + Expect(err).ToNot(HaveOccurred()) + Expect(testService.GetScheduleCount()).To(Equal(2)) + }) + }) + Describe("Plugin Unload", func() { It("should cancel all schedules when plugin is unloaded", func() { _, err := testService.ScheduleRecurring(GinkgoT().Context(), "@every 10s", "data1", "unload-1")