1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 19:24:42 +01:00

Improve tests

This commit is contained in:
Daniil Gentili 2023-11-30 17:44:10 +01:00
parent 47eac0ac20
commit 7394ecfa79
5 changed files with 49 additions and 7 deletions

View File

@ -29,6 +29,25 @@ steps:
event: event:
- tag - tag
- push - push
secrets:
- API_ID
- API_HASH
- BOT_TOKEN
- DEST
environment:
- PHP_VERSION=${php}
- PLATFORM=${platform}
- TAG=${CI_COMMIT_TAG}
commands:
- apk add bash
- tests/test.sh
- php tests/handshake.php
- composer test
test_pr:
group: test
image: danog/madelineproto:next
when:
event:
- pull_request - pull_request
environment: environment:
- PHP_VERSION=${php} - PHP_VERSION=${php}

View File

@ -110,7 +110,8 @@
"build": [ "build": [
"@docs", "@docs",
"@docs-fix", "@docs-fix",
"@cs-fix" "@cs-fix",
"@psalm"
], ],
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v",
"psalm": "psalm --no-cache --threads=10", "psalm": "psalm --no-cache --threads=10",

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace danog\MadelineProto\Test; namespace danog\MadelineProto\Test;
use Amp\Process\Process;
use Amp\Socket\InternetAddress; use Amp\Socket\InternetAddress;
use danog\MadelineProto\API; use danog\MadelineProto\API;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
@ -27,6 +28,7 @@ use React\EventLoop\Loop;
use React\Socket\ServerInterface; use React\Socket\ServerInterface;
use Throwable; use Throwable;
use function Amp\ByteStream\splitLines;
use function Amp\delay; use function Amp\delay;
\define('MADELINEPROTO_TEST', 'pony'); \define('MADELINEPROTO_TEST', 'pony');
@ -36,8 +38,7 @@ final class DataCenterTest extends TestCase
{ {
private static API $main; private static API $main;
private static API $test; private static API $test;
private static LeProxyServer $proxy; private static Process $proxy;
private static ServerInterface $proxySocket;
private static InternetAddress $proxyEndpoint; private static InternetAddress $proxyEndpoint;
private static function getBaseSettings(bool $test): Settings private static function getBaseSettings(bool $test): Settings
@ -61,9 +62,11 @@ final class DataCenterTest extends TestCase
if (isset(self::$proxy)) { if (isset(self::$proxy)) {
return; return;
} }
self::$proxy = new LeProxyServer(Loop::get()); self::$proxy = Process::start([PHP_BINARY, __DIR__.'/../../../vendor-bin/leproxy/proxy.php']);
self::$proxySocket = self::$proxy->listen('127.0.0.1:0', false); foreach (splitLines(self::$proxy->getStdout()) as $addr) {
self::$proxyEndpoint = InternetAddress::fromString(str_replace('tcp://', '', self::$proxySocket->getAddress())); break;
}
self::$proxyEndpoint = InternetAddress::fromString(str_replace('tcp://', '', $addr));
self::$main = new API( self::$main = new API(
sys_get_temp_dir().'/testing_datacenter_main.madeline', sys_get_temp_dir().'/testing_datacenter_main.madeline',
@ -137,7 +140,8 @@ final class DataCenterTest extends TestCase
} }
$testedProxies = false; $testedProxies = false;
foreach ([WssStream::class, DefaultStream::class, WsStream::class] as $transport) { //foreach ([WssStream::class, DefaultStream::class, WsStream::class] as $transport) {
foreach ([DefaultStream::class] as $transport) {
foreach ([true, false] as $obfuscated) { foreach ([true, false] as $obfuscated) {
if ($transport !== DefaultStream::class && !$obfuscated) { if ($transport !== DefaultStream::class && !$obfuscated) {
continue; continue;

View File

@ -0,0 +1,5 @@
{
"require": {
"leproxy/leproxy": "dev-main"
}
}

View File

@ -0,0 +1,13 @@
<?php
use LeProxy\LeProxy\LeProxyServer;
use React\EventLoop\Loop;
require __DIR__.'/vendor/autoload.php';
$proxy = new LeProxyServer(Loop::get());
$proxySocket = $proxy->listen('127.0.0.1:0', false);
echo $proxySocket->getAddress().PHP_EOL;
Loop::run();