Skip to content

Commit

Permalink
test: ttlConfig expiration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Oct 12, 2023
1 parent 469373f commit 57d56ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/ttlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TTLConfig<T extends TTLConfig.Options, P extends JsonMap> extends C
const date = new Date().getTime();
// delete all the expired entries
Object.entries(contents)
.filter(([, value]) => !this.isExpired(date, value))
.filter(([, value]) => this.isExpired(date, value))
.map(([key]) => this.unset(key));
}

Expand Down
27 changes: 27 additions & 0 deletions test/unit/config/ttlConfigTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,31 @@ describe('TTLConfig', () => {
expect(isExpired).to.be.false;
});
});

describe.only('filters expired keys on init', () => {
$$.setConfigStubContents('TestConfig', {
contents: {
old: {
value: 1,
timestamp: new Date().getTime() - Duration.days(7).milliseconds,
},
current: {
value: 2,
timestamp: new Date().getTime(),
},
future: {
value: 3,
timestamp: new Date().getTime() + Duration.days(7).milliseconds,
},
},
});

it('should omit expired keys', async () => {
const config = await TestConfig.create();
const keys = config.keys();
expect(keys).to.include('current');
expect(keys).to.include('future');
expect(keys).to.not.include('old');
});
});
});

4 comments on commit 57d56ce

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 57d56ce Previous: 469373f Ratio
Child logger creation 531040 ops/sec (±0.44%) 440373 ops/sec (±0.96%) 0.83
Logging a string on root logger 451216 ops/sec (±11.25%) 373009 ops/sec (±11.79%) 0.83
Logging an object on root logger 315458 ops/sec (±14.19%) 227600 ops/sec (±15.53%) 0.72
Logging an object with a message on root logger 233624 ops/sec (±10.88%) 167706 ops/sec (±23.20%) 0.72
Logging an object with a redacted prop on root logger 262983 ops/sec (±14.39%) 148543 ops/sec (±24.92%) 0.56
Logging a nested 3-level object on root logger 3501 ops/sec (±212.85%) 116594 ops/sec (±24.07%) 33.30

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 57d56ce Previous: 469373f Ratio
Logging a nested 3-level object on root logger 3501 ops/sec (±212.85%) 116594 ops/sec (±24.07%) 33.30

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 57d56ce Previous: 469373f Ratio
Child logger creation 469189 ops/sec (±6.36%) 480185 ops/sec (±7.93%) 1.02
Logging a string on root logger 604484 ops/sec (±13.38%) 550872 ops/sec (±9.13%) 0.91
Logging an object on root logger 415660 ops/sec (±15.34%) 304616 ops/sec (±21.01%) 0.73
Logging an object with a message on root logger 261242 ops/sec (±12.69%) 150339 ops/sec (±27.34%) 0.58
Logging an object with a redacted prop on root logger 12185 ops/sec (±186.83%) 180772 ops/sec (±20.15%) 14.84
Logging a nested 3-level object on root logger 284729 ops/sec (±7.62%) 117672 ops/sec (±22.59%) 0.41

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 57d56ce Previous: 469373f Ratio
Logging an object with a redacted prop on root logger 12185 ops/sec (±186.83%) 180772 ops/sec (±20.15%) 14.84

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.