Skip to content

Fix tests for running locally #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ RUN apt-get update \
# For rewrite rules
&& a2enmod rewrite \
# Needed for gluedev/laravel-stackdriver
&& pecl install opencensus-alpha \
&& docker-php-ext-enable opencensus \
&& pecl install opencensus-alpha xdebug \
&& docker-php-ext-enable opencensus xdebug \
&& rm -rf /var/lib/apt/lists/*

ENV APACHE_DOCUMENT_ROOT /var/www/html/public

RUN echo "zend_extension=xdebug\n\n\
[xdebug]\n\
xdebug.mode=develop,debug\n\
xdebug.client_host=192.168.1.13\n\
xdebug.client_port=9003\n\
" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Change the document root
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
&& sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
Expand Down
13 changes: 7 additions & 6 deletions tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Jobs\CirrusSearch\ElasticSearchIndexInit;
use App\Http\Curl\HttpRequest;
Expand All @@ -18,7 +19,7 @@

class ElasticSearchIndexInitTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
use DispatchesJobs;

private $wiki;
Expand Down Expand Up @@ -95,7 +96,7 @@ public function testSuccess()

// feature should get enabled
$this->assertSame(
1,
1,
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count()
);
}
Expand Down Expand Up @@ -125,7 +126,7 @@ public function testUpdate()

// feature should get enabled
$this->assertSame(
1,
1,
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count()
);
}
Expand All @@ -150,16 +151,16 @@ public function testFailure( $request, string $expectedFailure, $mockResponse )
$mockJob->expects($this->once())
->method('fail')
->with(new \RuntimeException(str_replace('<WIKI_ID>', $this->wiki->id, $expectedFailure)));

$request->method('execute')->willReturn(json_encode($mockResponse));

$job = new ElasticSearchIndexInit($this->wiki->id);
$job->setJob($mockJob);
$job->handle($request);


$this->assertSame(
0,
0,
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count()
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Jobs/CirrusSearch/ForceSearchIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Jobs\CirrusSearch\ElasticSearchIndexInit;
use App\Http\Curl\HttpRequest;
Expand All @@ -22,7 +23,7 @@

class ForceSearchIndexTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
use DispatchesJobs;
private $wiki;
private $wikiDb;
Expand Down
5 changes: 3 additions & 2 deletions tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Jobs\CirrusSearch\ElasticSearchIndexInit;
use App\Http\Curl\HttpRequest;
Expand All @@ -22,7 +23,7 @@

class QueueSearchIndexBatchesTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
use DispatchesJobs;

private $wiki;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function setUp(): void {
public function testSuccess()
{
Queue::fake();

$mockResponse = [
'warnings' => [],
'wbstackQueueSearchIndexBatches' => [
Expand Down
14 changes: 7 additions & 7 deletions tests/Jobs/DeleteQueryserviceNamespaceJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Jobs;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Http\Curl\HttpRequest;
use App\Jobs\DeleteQueryserviceNamespaceJob;
Expand All @@ -16,7 +16,7 @@

class DeleteQueryserviceNamespaceJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;

public function testDeleteNamespace()
{
Expand Down Expand Up @@ -44,8 +44,8 @@ public function testDeleteNamespace()

$request->expects($this->exactly(1))
->method('setOptions')
->with(
[
->with(
[
CURLOPT_URL => $dbRow->backend.'/bigdata/namespace/' . $namespace,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
Expand All @@ -59,12 +59,12 @@ public function testDeleteNamespace()
]
]);


$job = new DeleteQueryserviceNamespaceJob($wiki->id);
$job->handle( $request );

$this->assertSame(
0,
0,
QueryserviceNamespace::where( ['namespace' => $namespace ])->count()
);
}
Expand Down Expand Up @@ -105,4 +105,4 @@ public function testNoNamespace() {
$job->handle($request);
}

}
}
15 changes: 8 additions & 7 deletions tests/Jobs/DeleteWikiDispatcherJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Jobs;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\QueryserviceNamespace;
use Illuminate\Contracts\Queue\Job;
Expand All @@ -29,7 +29,7 @@

class DeleteWikiDispatcherJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;

public function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -94,6 +94,7 @@ public function testNothingDispatchesUntilItsTime() {
$job->handle();

Log::assertLogged('info', function ($message, $context) {
echo $message;
return Str::contains($message, 'Found no soft deleted wikis over threshold. exiting.');
});

Expand All @@ -120,10 +121,10 @@ public function testDeleteWithOptionalResources()
$this->assertNotNull($nsAssignment);

WikiSetting::factory()->create(
[
[
'wiki_id' => $this->wiki->id,
'name' => WikiSetting::wwExtEnableElasticSearch,
'value' => true
'value' => true
]
);

Expand All @@ -147,7 +148,7 @@ public function testDeleteWithOptionalResources()
public function testActuallyRunningJobsThatDelete()
{
$this->wiki->update(['domain' => 'asdasdaf' . Config::get('wbstack.subdomain_suffix')]);

// create db to be deleted
$job = new ProvisionWikiDbJob('great_job', 'the_test_database', null);
$job->handle( $this->app->make('db') );
Expand All @@ -159,7 +160,7 @@ public function testActuallyRunningJobsThatDelete()

$this->assertTrue( $res );
$this->assertNotNull( WikiDb::where([ 'wiki_id' => $this->wiki->id ])->first() );

$mockJob = $this->createMock(Job::class);
$job = new DeleteWikiDispatcherJob();
$job->setJob($mockJob);
Expand All @@ -177,4 +178,4 @@ public function testActuallyRunningJobsThatDelete()
$mockJob->expects($this->never())->method('fail');
}

}
}
3 changes: 2 additions & 1 deletion tests/Jobs/DeleteWikiFinalizeJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\WikiManager;
use App\Wiki;
Expand All @@ -18,7 +19,7 @@

class DeleteWikiFinalizeJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;

public function setUp(): void {
parent::setUp();
Expand Down
20 changes: 6 additions & 14 deletions tests/Jobs/DeleteWikiJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Jobs;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Jobs\DeleteWikiDbJob;
use App\User;
Expand All @@ -20,18 +20,10 @@

class DeleteWikiJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
use DispatchesJobs;

private $wiki;
protected $connectionsToTransact = ['mysql', 'mw'];

protected function setUp(): void {
parent::setUp();
DB::delete( "DELETE FROM wiki_dbs WHERE name='the_test_database';" );
DB::delete( "DELETE FROM wiki_dbs WHERE name='the_test_database_not_to_be_deleted';" );
DB::connection('mysql')->getPdo()->exec('DROP DATABASE IF EXISTS the_test_database; DROP DATABASE IF EXISTS the_test_database_not_to_be_deleted');
}

private function getExpectedDeletedDatabaseName( $wiki ): string {
return "mwdb_deleted_1631534400_" . $wiki->id;
Expand Down Expand Up @@ -78,13 +70,13 @@ public function testDeletesWiki()

// Would be injected by the app
$manager = $this->app->make('db');

$job = new ProvisionWikiDbJob($databases[0]['prefix'], $databases[0]['name'], null);
$job->handle($manager);

// Would be injected by the app
$manager = $this->app->make('db');

$job = new ProvisionWikiDbJob($databases[1]['prefix'], $databases[1]['name'], null);
$job->handle($manager);

Expand Down Expand Up @@ -117,7 +109,7 @@ public function testDeletesWiki()

// this job will kill the underlying connection
$job = new DeleteWikiDbJob( $this->wiki->id );
$job->setJob($mockJob);
// $job->setJob($mockJob);
$job->handle($manager);

// get a new connection and take a look at the database tables and newly created databases
Expand Down Expand Up @@ -167,7 +159,7 @@ public function testFailure( $wiki_id, $deleted_at, string $expectedFailure)
$mockJob->expects($this->once())
->method('fail')
->with(new \RuntimeException(str_replace('<WIKI_ID>', $wiki_id, $expectedFailure)));

$job = new DeleteWikiDbJob($wiki_id);
$job->setJob($mockJob);
$job->handle($mockMananger);
Expand Down
14 changes: 8 additions & 6 deletions tests/Jobs/ElasticSearch/ElasticSearchIndexDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Http\Curl\HttpRequest;
use App\WikiManager;
Expand All @@ -16,7 +17,8 @@

class ElasticSearchIndexDeleteTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;

private $wiki;
private $user;
private $wikiDb;
Expand Down Expand Up @@ -57,7 +59,7 @@ public function testDeletesElasticSearchIndex()

$request->expects($this->exactly(2))
->method('setOptions')
->withConsecutive(
->withConsecutive(
[[
CURLOPT_URL => $this->elasticSearchHost.'/_cat/indices/'.$this->wikiDb->name.'*?v&s=index&h=index',
CURLOPT_RETURNTRANSFER => true,
Expand All @@ -74,7 +76,7 @@ public function testDeletesElasticSearchIndex()
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
]]);


$mockJob = $this->createMock(Job::class);
$mockJob->expects($this->never())->method('fail');
Expand All @@ -85,7 +87,7 @@ public function testDeletesElasticSearchIndex()

// feature should get disabled
$this->assertSame(
1,
1,
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => false])->count()
);
}
Expand Down Expand Up @@ -113,9 +115,9 @@ public function testFailure( $request, string $expectedFailure, $mockResponse, $
$job = new ElasticSearchIndexDelete($this->wiki->id);
$job->setJob($mockJob);
$job->handle( $request );

$this->assertSame(
1,
1,
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => $settingStateInDatabase])->count()
);

Expand Down
Loading