Skip to content

HedgeConfig.ofDefaults() creates an unusable default duration supplier #2457

Description

@023-dev

Description

HedgeConfig.ofDefaults() currently creates a config whose duration supplier type is PRECONFIGURED, but the configured cutoff duration is null.

This means HedgeDurationSupplier.fromConfig(HedgeConfig.ofDefaults()) creates a PreconfiguredDurationSupplier with a null cutoff. The supplier can then return null, and the default Hedge execution path may fail later when HedgeImpl calls durationSupplier.get().toNanos().

There is a related copy-builder issue in HedgeConfig.from(...): HedgeConfig.Builder(HedgeConfig baseConfig) does not copy durationSupplierType from the source config. As a result, a config using AVERAGE_PLUS can silently become PRECONFIGURED after being copied.

Tests

The issue can be reproduced by adding the following tests to HedgeConfigTest. When executed, shouldCreateUsableDefaultDurationSupplier fails because the default duration supplier returns null, and shouldInitializeDurationSupplierTypeFromOtherConfig fails because the copied config's supplier type is PRECONFIGURED instead of the expected AVERAGE_PLUS.

@Test
public void shouldCreateUsableDefaultDurationSupplier() {
    HedgeDurationSupplier supplier = HedgeDurationSupplier.fromConfig(HedgeConfig.ofDefaults());

    then(supplier.get()).isNotNull();
}

@Test
public void shouldInitializeDurationSupplierTypeFromOtherConfig() {
    HedgeConfig config = HedgeConfig.custom()
        .averagePlusAmountDuration(200, false, 100).build();

    HedgeConfig copiedConfig = HedgeConfig.from(config).build();

    then(copiedConfig.getDurationSupplier())
        .isEqualTo(HedgeConfig.HedgeDurationSupplierType.AVERAGE_PLUS);
}

Failure result:

HedgeConfigTest > shouldInitializeDurationSupplierTypeFromOtherConfig FAILED
    org.opentest4j.AssertionFailedError at HedgeConfigTest.java:70

HedgeConfigTest > shouldCreateUsableDefaultDurationSupplier FAILED
    java.lang.AssertionError at HedgeConfigTest.java:59

Expected behavior

  • HedgeConfig.ofDefaults() should create a usable default duration supplier.
  • HedgeConfig.from(existingConfig).build() should preserve the source config's duration supplier type.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions