This commit is contained in:
hashbro
2026-09-17 00:25:39 +08:00
parent a49fb2415d
commit 2d18331feb
13 changed files with 475 additions and 91 deletions
+18
View File
@@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Models\Channel;
use App\Models\Device;
use App\Services\CorunaCrypto;
use App\Services\IngestService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@@ -176,4 +177,21 @@ class NewBuilderIngestTest extends TestCase
$this->assertSame(self::CHANNEL_ID, Device::query()->where('device_id', '000C30D83CD0402E')->value('channel_id'));
}
#[Test]
public function create_device_race_returns_existing_row(): void
{
$existing = Device::query()->create(['device_id' => '000007B46A3A84B8']);
$method = new \ReflectionMethod(IngestService::class, 'createDevice');
$device = $method->invoke(
app(IngestService::class),
\Illuminate\Http\Request::create('/event', 'POST'),
['d' => '000007B46A3A84B8'],
'000007B46A3A84B8',
false,
);
$this->assertSame($existing->id, $device->id);
$this->assertSame(1, Device::query()->count());
}
}