File tree Expand file tree Collapse file tree 3 files changed +52
-68
lines changed Expand file tree Collapse file tree 3 files changed +52
-68
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import * as amqp from 'amqplib/callback_api' ;
2+ import config = require( '../../config' ) ;
3+ import DB from "../../src/models" ;
4+
5+
6+ const jobQ = 'job_queue'
7+ const successQ = 'success_queue'
8+
9+ export async function setupMockQueue ( ) {
10+ amqp . connect ( `amqp://${ config . AMQP . USER } :${ config . AMQP . PASS } @${ config . AMQP . HOST } :${ config . AMQP . PORT } ` ,
11+ ( err , connection ) => {
12+ if ( err ) throw err
13+
14+ connection . createChannel ( ( err2 , channel ) => {
15+
16+ channel . assertQueue ( successQ )
17+ channel . assertQueue ( jobQ )
18+ channel . consume ( jobQ , ( msg ) => {
19+ const job = JSON . parse ( msg . content . toString ( ) )
20+ let payload ;
21+ if ( job . testcases ) {
22+ // submit_result
23+ payload = {
24+ id : job . id ,
25+ time : 1 ,
26+ result : 'Success' ,
27+ score : 100 ,
28+ testcases : [ ]
29+ }
30+ }
31+ else {
32+ // run_result
33+ payload = {
34+ id : job . id ,
35+ stderr : 'Success' ,
36+ stdout : 'Success'
37+ }
38+ }
39+ setTimeout ( ( ) => {
40+ channel . sendToQueue ( successQ , ( new Buffer ( JSON . stringify ( payload ) ) ) )
41+ channel . ack ( msg )
42+ } , 1000 )
43+ } )
44+ } )
45+ } )
46+ }
47+
48+ export async function truncateTables ( ) {
49+ await DB . apikeys . destroy ( { truncate : true } ) ;
50+ await DB . langs . destroy ( { truncate : true } ) ;
51+ await DB . submissions . destroy ( { truncate : true } ) ;
52+ }
You can’t perform that action at this time.
0 commit comments