@@ -25,6 +25,9 @@ func TestDefaultConfigIncludesMetricsSettings(t *testing.T) {
2525 if cfg .Metrics .ResourceRefreshInterval != "120s" {
2626 t .Fatalf ("expected default metrics.resource_refresh_interval to be 120s, got %q" , cfg .Metrics .ResourceRefreshInterval )
2727 }
28+ if cfg .Metrics .AllocationReconcileInterval != "120s" {
29+ t .Fatalf ("expected default metrics.allocation_reconcile_interval to be 120s, got %q" , cfg .Metrics .AllocationReconcileInterval )
30+ }
2831 if cfg .Otel .MetricExportInterval != "60s" {
2932 t .Fatalf ("expected default otel.metric_export_interval to be 60s, got %q" , cfg .Otel .MetricExportInterval )
3033 }
@@ -40,15 +43,20 @@ func TestDefaultConfigIncludesMetricsSettings(t *testing.T) {
4043 if len (cfg .Images .AutoDelete .Allowed ) != 0 {
4144 t .Fatalf ("expected default images.auto_delete.allowed to be empty, got %v" , cfg .Images .AutoDelete .Allowed )
4245 }
46+ if cfg .Instances .LifecycleEventBufferSize != 256 {
47+ t .Fatalf ("expected default instances.lifecycle_event_buffer_size to be 256, got %d" , cfg .Instances .LifecycleEventBufferSize )
48+ }
4349}
4450
4551func TestLoadEnvOverridesMetricsAndOtelInterval (t * testing.T ) {
4652 t .Setenv ("METRICS__LISTEN_ADDRESS" , "0.0.0.0" )
4753 t .Setenv ("METRICS__PORT" , "9999" )
4854 t .Setenv ("METRICS__VM_LABEL_BUDGET" , "350" )
4955 t .Setenv ("METRICS__RESOURCE_REFRESH_INTERVAL" , "30s" )
56+ t .Setenv ("METRICS__ALLOCATION_RECONCILE_INTERVAL" , "45s" )
5057 t .Setenv ("OTEL__METRIC_EXPORT_INTERVAL" , "15s" )
5158 t .Setenv ("OTEL__SUCCESSFUL_GET_SAMPLE_RATIO" , "0.25" )
59+ t .Setenv ("INSTANCES__LIFECYCLE_EVENT_BUFFER_SIZE" , "512" )
5260
5361 tmp := t .TempDir ()
5462 cfgPath := filepath .Join (tmp , "config.yaml" )
@@ -73,12 +81,18 @@ func TestLoadEnvOverridesMetricsAndOtelInterval(t *testing.T) {
7381 if cfg .Metrics .ResourceRefreshInterval != "30s" {
7482 t .Fatalf ("expected metrics.resource_refresh_interval override, got %q" , cfg .Metrics .ResourceRefreshInterval )
7583 }
84+ if cfg .Metrics .AllocationReconcileInterval != "45s" {
85+ t .Fatalf ("expected metrics.allocation_reconcile_interval override, got %q" , cfg .Metrics .AllocationReconcileInterval )
86+ }
7687 if cfg .Otel .MetricExportInterval != "15s" {
7788 t .Fatalf ("expected otel.metric_export_interval override, got %q" , cfg .Otel .MetricExportInterval )
7889 }
7990 if cfg .Otel .SuccessfulGetSampleRatio != 0.25 {
8091 t .Fatalf ("expected otel.successful_get_sample_ratio override, got %v" , cfg .Otel .SuccessfulGetSampleRatio )
8192 }
93+ if cfg .Instances .LifecycleEventBufferSize != 512 {
94+ t .Fatalf ("expected instances.lifecycle_event_buffer_size override, got %d" , cfg .Instances .LifecycleEventBufferSize )
95+ }
8296}
8397
8498func TestValidateRejectsInvalidMetricsPort (t * testing.T ) {
@@ -147,6 +161,59 @@ func TestValidateRejectsInvalidResourceRefreshInterval(t *testing.T) {
147161 }
148162}
149163
164+ func TestValidateRejectsInvalidAllocationReconcileInterval (t * testing.T ) {
165+ cfg := defaultConfig ()
166+ cfg .Metrics .AllocationReconcileInterval = ""
167+
168+ err := cfg .Validate ()
169+ if err == nil {
170+ t .Fatalf ("expected validation error for empty allocation reconcile interval" )
171+ }
172+
173+ cfg = defaultConfig ()
174+ cfg .Metrics .AllocationReconcileInterval = "not-a-duration"
175+
176+ err = cfg .Validate ()
177+ if err == nil {
178+ t .Fatalf ("expected validation error for invalid allocation reconcile interval" )
179+ }
180+
181+ cfg = defaultConfig ()
182+ cfg .Metrics .AllocationReconcileInterval = "0s"
183+
184+ err = cfg .Validate ()
185+ if err == nil {
186+ t .Fatalf ("expected validation error for non-positive allocation reconcile interval" )
187+ }
188+ }
189+
190+ func TestLoadUsesConfiguredLifecycleEventBufferSize (t * testing.T ) {
191+ tmp := t .TempDir ()
192+ cfgPath := filepath .Join (tmp , "config.yaml" )
193+ if err := os .WriteFile (cfgPath , []byte ("instances:\n lifecycle_event_buffer_size: 384\n " ), 0600 ); err != nil {
194+ t .Fatalf ("write temp config: %v" , err )
195+ }
196+
197+ cfg , err := Load (cfgPath )
198+ if err != nil {
199+ t .Fatalf ("load config: %v" , err )
200+ }
201+
202+ if cfg .Instances .LifecycleEventBufferSize != 384 {
203+ t .Fatalf ("expected instances.lifecycle_event_buffer_size from config file, got %d" , cfg .Instances .LifecycleEventBufferSize )
204+ }
205+ }
206+
207+ func TestValidateRejectsInvalidLifecycleEventBufferSize (t * testing.T ) {
208+ cfg := defaultConfig ()
209+ cfg .Instances .LifecycleEventBufferSize = 0
210+
211+ err := cfg .Validate ()
212+ if err == nil {
213+ t .Fatalf ("expected validation error for invalid lifecycle event buffer size" )
214+ }
215+ }
216+
150217func TestLoadUsesDefaultImageAutoDeleteRetentionWindow (t * testing.T ) {
151218 tmp := t .TempDir ()
152219 cfgPath := filepath .Join (tmp , "config.yaml" )
0 commit comments