Skip to content

Commit

Permalink
Only collect queries we care about to remove trimming concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Feb 19, 2024
1 parent 1362cb6 commit 8e67451
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions tests/Feature/Storage/DatabaseStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@
});

it('combines duplicate count aggregates before upserting', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$queries = collect();
DB::listen(fn ($query) => $queries[] = $query);
DB::listen(function (QueryExecuted $event) use (&$queries) {
if (str_starts_with($event->sql, 'insert')) {
$queries[] = $event;
}
});

Pulse::record('type', 'key1')->count();
Pulse::record('type', 'key1')->count();
Expand All @@ -150,9 +153,12 @@
});

it('combines duplicate min aggregates before upserting', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$queries = collect();
DB::listen(fn ($query) => $queries[] = $query);
DB::listen(function (QueryExecuted $event) use (&$queries) {
if (str_starts_with($event->sql, 'insert')) {
$queries[] = $event;
}
});

Pulse::record('type', 'key1', 200)->min();
Pulse::record('type', 'key1', 100)->min();
Expand All @@ -177,9 +183,12 @@
});

it('combines duplicate max aggregates before upserting', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$queries = collect();
DB::listen(fn ($query) => $queries[] = $query);
DB::listen(function (QueryExecuted $event) use (&$queries) {
if (str_starts_with($event->sql, 'insert')) {
$queries[] = $event;
}
});

Pulse::record('type', 'key1', 100)->max();
Pulse::record('type', 'key1', 300)->max();
Expand All @@ -204,9 +213,12 @@
});

it('combines duplicate sum aggregates before upserting', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$queries = collect();
DB::listen(fn ($query) => $queries[] = $query);
DB::listen(function (QueryExecuted $event) use (&$queries) {
if (str_starts_with($event->sql, 'insert')) {
$queries[] = $event;
}
});

Pulse::record('type', 'key1', 100)->sum();
Pulse::record('type', 'key1', 300)->sum();
Expand All @@ -231,9 +243,12 @@
});

it('combines duplicate average aggregates before upserting', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$queries = collect();
DB::listen(fn ($query) => $queries[] = $query);
DB::listen(function (QueryExecuted $event) use (&$queries) {
if (str_starts_with($event->sql, 'insert')) {
$queries[] = $event;
}
});

Pulse::record('type', 'key1', 100)->avg();
Pulse::record('type', 'key1', 300)->avg();
Expand Down Expand Up @@ -464,10 +479,11 @@
});

it('collapses values with the same key into a single upsert', function () {
Config::set('pulse.ingest.trim.lottery', [0, 1]);
$bindings = [];
DB::listen(function (QueryExecuted $event) use (&$bindings) {
$bindings = $event->bindings;
if (str_starts_with($event->sql, 'insert')) {
$bindings = $event->bindings;
}
});

Pulse::set('read_counter', 'post:321', 123);
Expand Down

0 comments on commit 8e67451

Please sign in to comment.