diff --git a/.github/workflows/split-testing.yml b/.github/workflows/split-testing.yml index 68fa8f3b6..e52809627 100644 --- a/.github/workflows/split-testing.yml +++ b/.github/workflows/split-testing.yml @@ -1,4 +1,4 @@ -name: 'Ecotone Framework' +name: 'Tests' on: pull_request: @@ -10,7 +10,7 @@ on: jobs: get_packages: - name: Package testing + name: Get packages runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test-monorepo.yml b/.github/workflows/test-monorepo.yml index 99eaf3f45..bada59558 100644 --- a/.github/workflows/test-monorepo.yml +++ b/.github/workflows/test-monorepo.yml @@ -1,4 +1,4 @@ -name: 'Ecotone Framework' +name: 'Tests' on: pull_request: @@ -10,7 +10,7 @@ on: jobs: run: - name: "Testing Monorepo" + name: "Monorepo" runs-on: ${{ matrix.operating-system }} strategy: matrix: @@ -118,3 +118,11 @@ jobs: APP_DB_HOST: 127.0.0.1 APP_DB_PORT: 3306 APP_DB_DRIVER: pdo_mysql + + - name: Benchmarks + run: composer tests:phpbench + env: + DATABASE_DSN: pgsql://ecotone:secret@127.0.0.1:5432/ecotone + APP_DB_HOST: 127.0.0.1 + APP_DB_PORT: 5432 + APP_DB_DRIVER: pdo_pgsql diff --git a/composer.json b/composer.json index e658b7fb0..c18134d8c 100644 --- a/composer.json +++ b/composer.json @@ -137,7 +137,8 @@ "aws/aws-sdk-php": "<=3.269.5", "symfony/messenger": "^5.4|^6.0", "symfony/doctrine-messenger": "^5.4|^6.0", - "doctrine/doctrine-bundle": "^2.9" + "doctrine/doctrine-bundle": "^2.9", + "phpbench/phpbench": "^1.2" }, "extra": { "laravel": { @@ -174,6 +175,11 @@ "@tests:phpstan", "@tests:phpunit", "@tests:behat" + ], + "tests:phpbench": [ + "(cd packages/Ecotone && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)", + "(cd packages/Laravel && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)", + "(cd packages/Symfony && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)" ] }, "config": { diff --git a/packages/Ecotone/composer.json b/packages/Ecotone/composer.json index ac2e8b2ff..c0fe1a450 100644 --- a/packages/Ecotone/composer.json +++ b/packages/Ecotone/composer.json @@ -44,7 +44,8 @@ "phpunit/phpunit": "^9.5", "behat/behat": "^3.10", "phpstan/phpstan": "^1.8", - "symfony/expression-language": "^6.0" + "symfony/expression-language": "^6.0", + "phpbench/phpbench": "^1.2" }, "scripts": { "tests:phpstan": "vendor/bin/phpstan", @@ -54,6 +55,9 @@ "tests:behat": [ "vendor/bin/behat -vvv" ], + "tests:phpbench": [ + "vendor/bin/phpbench run tests/Benchmark --bootstrap=./vendor/autoload.php" + ], "tests:ci": [ "@tests:phpstan", "@tests:phpunit", diff --git a/packages/Ecotone/tests/Benchmark/EcotoneBenchmark.php b/packages/Ecotone/tests/Benchmark/EcotoneBenchmark.php new file mode 100644 index 000000000..edf5fbbc8 --- /dev/null +++ b/packages/Ecotone/tests/Benchmark/EcotoneBenchmark.php @@ -0,0 +1,82 @@ +execute( + ServiceConfiguration::createWithDefaults() + ->withFailFast(false) + ->withSkippedModulePackageNames(ModulePackageList::allPackages()), + false + ); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_running_ecotone_lite_with_fail_fast() + { + $this->execute( + ServiceConfiguration::createWithDefaults() + ->withFailFast(true) + ->withSkippedModulePackageNames(ModulePackageList::allPackages()), + false + ); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_running_ecotone_lite_with_cache() + { + $this->execute( + ServiceConfiguration::createWithDefaults() + ->withFailFast(false) + ->withCacheDirectoryPath(sys_get_temp_dir()) + ->withSkippedModulePackageNames(ModulePackageList::allPackages()), + true + ); + } + + private function execute(ServiceConfiguration $serviceConfiguration, bool $useCachedVersion): void + { + $ecotoneApplication = EcotoneLite::bootstrap( + [Merchant::class, User::class, MerchantSubscriber::class, InMemoryStandardRepository::class], + [ + new MerchantSubscriber(), InMemoryStandardRepository::createEmpty() + ], + $serviceConfiguration, + useCachedVersion: $useCachedVersion, + allowGatewaysToBeRegisteredInContainer: true + ); + + $merchantId = '123'; + $ecotoneApplication->getCommandBus()->send(new CreateMerchant($merchantId)); + + $this->assertTrue( + $ecotoneApplication->getQueryBus()->sendWithRouting('user.get', metadata: ['aggregate.id' => $merchantId]) + ); + } +} diff --git a/packages/Laravel/composer.json b/packages/Laravel/composer.json index 3677f5420..af26bbb35 100644 --- a/packages/Laravel/composer.json +++ b/packages/Laravel/composer.json @@ -43,7 +43,8 @@ "phpstan/phpstan": "^1.8", "orchestra/testbench": "^7.6", "wikimedia/composer-merge-plugin": "^2.0", - "symfony/expression-language": "^6.0" + "symfony/expression-language": "^6.0", + "phpbench/phpbench": "^1.2" }, "extra": { "laravel": { @@ -68,6 +69,9 @@ "tests:phpunit": [ "vendor/bin/phpunit" ], + "tests:phpbench": [ + "vendor/bin/phpbench run tests/Application/Benchmark --bootstrap=./vendor/autoload.php" + ], "tests:ci": [ "@tests:phpstan", "@tests:phpunit" diff --git a/packages/Laravel/src/EcotoneProvider.php b/packages/Laravel/src/EcotoneProvider.php index 36fd6b823..7b272fa54 100644 --- a/packages/Laravel/src/EcotoneProvider.php +++ b/packages/Laravel/src/EcotoneProvider.php @@ -43,7 +43,7 @@ public function register() $environment = App::environment(); $rootCatalog = App::basePath(); - $isCachingConfiguration = $environment === 'prod' ? true : Config::get('ecotone.cacheConfiguration'); + $isCachingConfiguration = in_array($environment, ['prod', 'production']) ? true : Config::get('ecotone.cacheConfiguration'); $cacheDirectory = App::storagePath() . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'ecotone'; if (! is_dir($cacheDirectory)) { diff --git a/packages/Laravel/tests/Application/Benchmark/EcotoneBenchmark.php b/packages/Laravel/tests/Application/Benchmark/EcotoneBenchmark.php new file mode 100644 index 000000000..a27663f19 --- /dev/null +++ b/packages/Laravel/tests/Application/Benchmark/EcotoneBenchmark.php @@ -0,0 +1,67 @@ +createApplication(); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_kernel_boot_on_dev() + { + putenv('APP_ENV=development'); + $this->createApplication(); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_messaging_boot_on_prod() + { + putenv('APP_ENV=production'); + $app = $this->createApplication(); + $app->make(ConfiguredMessagingSystem::class); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_messaging_boot_on_dev() + { + putenv('APP_ENV=development'); + $app = $this->createApplication(); + $app->make(ConfiguredMessagingSystem::class); + } + + public function createApplication(): Application + { + $app = require __DIR__ . '/../bootstrap/app.php'; + + $app->make(Kernel::class)->bootstrap(); + + return $app; + } +} diff --git a/packages/Symfony/tests/Benchmark/EcotoneBenchmark.php b/packages/Symfony/tests/Benchmark/EcotoneBenchmark.php new file mode 100644 index 000000000..c94aa05a9 --- /dev/null +++ b/packages/Symfony/tests/Benchmark/EcotoneBenchmark.php @@ -0,0 +1,55 @@ +boot(); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_kernel_boot_on_dev() + { + $kernel = new Kernel('dev', false); + $kernel->boot(); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_messaging_boot_on_prod() + { + $kernel = new Kernel('prod', false); + $kernel->boot(); + $kernel->getContainer()->get(ConfiguredMessagingSystem::class); + } + + /** + * @Revs(10) + * @Iterations(5) + * @Warmup(1) + */ + public function bench_messaging_boot_on_dev() + { + $kernel = new Kernel('dev', false); + $kernel->boot(); + $kernel->getContainer()->get(ConfiguredMessagingSystem::class); + } +} diff --git a/packages/Symfony/tests/Benchmark/KernelBootBench.php b/packages/Symfony/tests/Benchmark/KernelBootBench.php deleted file mode 100644 index acb9c46d6..000000000 --- a/packages/Symfony/tests/Benchmark/KernelBootBench.php +++ /dev/null @@ -1,32 +0,0 @@ -boot(); - } - - /** - * @Revs(10) - * @Iterations(5) - * @Warmup(1) - */ - public function benchKernelBootAndLoadMessagingSystem() - { - $kernel = new Kernel('prod', false); - $kernel->boot(); - $kernel->getContainer()->get(ConfiguredMessagingSystem::class); - } -}