### ----------------------------------------------------
### -- Test::Async
### -- Licenses: Artistic-2.0
### -- Authors: Vadim Belman <vrurg@cpan.org>
### -- File: t/170-heavily-concurrent.rakutest
### ----------------------------------------------------
use Test::Async <When Base>;

constant MAX-THREADS = 3000;
constant CONC-COUNT = 1100;
BEGIN {
    %*ENV<RAKUDO_MAX_THREADS> = MAX-THREADS;
    $*SCHEDULER = ThreadPoolScheduler.new: max_threads => MAX-THREADS;
}


my $count = 1000;

plan $count + 2,
    :parallel, :!random,
    :test-jobs(CONC-COUNT),
    :job-timeout(120),
    :when( <stress> );

is $*SCHEDULER.max_threads, MAX-THREADS, "max threads set";

my $starter = Promise.new;
my @job-promise;

for ^$count -> $id {
    @job-promise.push: my $p = Promise.new;
    subtest "test $id" => {
        $p.keep;
        await $starter;
        plan 1;
        pass "started $id";
    }
}

await @job-promise;
pass "all started";
$starter.keep;

done-testing;


