1- const child_process = require ( "child_process" ) ;
2- const { randomBytes } = require ( "crypto" ) ;
31const path = require ( "path" ) ;
42const fs = require ( "fs" ) ;
53
6- global . XMLHttpRequest = require ( "xmlhttprequest" ) . XMLHttpRequest ;
7-
8- const { ajax } = require ( "rxjs/ajax" ) ;
9-
10- const rxJupyter = require ( "rx-jupyter" ) ;
11-
124const _ = require ( "lodash" ) ;
135
14- console . log ( "running bookstore integration tests" ) ;
15-
16- async function genToken ( byteLength = 32 ) {
17- return new Promise ( ( resolve , reject ) => {
18- randomBytes ( byteLength , ( err , buffer ) => {
19- if ( err ) {
20- reject ( err ) ;
21- return ;
22- }
23-
24- resolve ( buffer . toString ( "hex" ) ) ;
25- } ) ;
26- } ) ;
27- }
6+ const s3 = require ( "./s3" ) ;
7+ const { JupyterServer } = require ( "./jupyter" ) ;
288
29- const sleep = timeout =>
30- new Promise ( ( resolve , reject ) => setTimeout ( resolve , timeout ) ) ;
9+ const { sleep } = require ( "./sleep" ) ;
3110
3211// Catch all rogue promise rejections to fail CI
3312process . on ( "unhandledRejection" , error => {
3413 console . log ( "unhandledRejection" , error . message ) ;
14+ console . error ( error . stack ) ;
3515 process . exit ( 2 ) ;
3616} ) ;
3717
38- var Minio = require ( "minio ") ;
18+ console . log ( "running bookstore integration tests ") ;
3919
4020const main = async ( ) => {
41- const jupyterToken = await genToken ( ) ;
42- const jupyterPort = 9988 ;
43- const jupyterEndpoint = `http://127.0.0.1:${ jupyterPort } ` ;
44-
4521 const bucketName = "bookstore" ;
46- // Optional according to minio docs, likely here for AWS compat
47- const regionName = "us-east-1" ;
22+
23+ const jupyterServer = new JupyterServer ( ) ;
24+ await jupyterServer . start ( ) ;
4825
4926 const s3Config = {
5027 endPoint : "127.0.0.1" ,
@@ -56,69 +33,11 @@ const main = async () => {
5633
5734 // Instantiate the minio client with the endpoint
5835 // and access keys as shown below.
59- var minioClient = new Minio . Client ( s3Config ) ;
60-
61- const madeBucket = await new Promise ( ( resolve , reject ) => {
62- minioClient . makeBucket ( bucketName , regionName , err => {
63- if ( err ) {
64- reject ( err ) ;
65- return ;
66- }
67- resolve ( ) ;
68- } ) ;
69- } ) ;
70- console . log ( `Created bucket ${ bucketName } ` ) ;
36+ var s3Client = new s3 . Client ( s3Config ) ;
7137
72- const jupyter = child_process . spawn (
73- "jupyter" ,
74- [
75- "notebook" ,
76- "--no-browser" ,
77- `--NotebookApp.token=${ jupyterToken } ` ,
78- `--NotebookApp.disable_check_xsrf=True` ,
79- `--port=${ jupyterPort } ` ,
80- `--ip=127.0.0.1`
81- ] ,
82- { cwd : __dirname }
83- ) ;
38+ await s3Client . makeBucket ( bucketName ) ;
8439
85- ////// Refactor me later, streams are a bit messy with async await
86- // Check to see that jupyter is up
87- let jupyterUp = false ;
88-
89- jupyter . stdout . on ( "data" , data => {
90- const s = data . toString ( ) ;
91- console . log ( s ) ;
92- } ) ;
93- jupyter . stderr . on ( "data" , data => {
94- const s = data . toString ( ) ;
95-
96- console . error ( s ) ;
97- if ( s . includes ( "Jupyter Notebook is running at" ) ) {
98- jupyterUp = true ;
99- }
100- } ) ;
101- jupyter . stdout . on ( "end" , data => console . log ( "DONE WITH JUPYTER" ) ) ;
102-
103- jupyter . on ( "exit" , code => {
104- if ( code != 0 ) {
105- // Jupyter exited badly
106- console . error ( "jupyter errored" , code ) ;
107- process . exit ( code ) ;
108- }
109- } ) ;
110-
111- await sleep ( 3000 ) ;
112-
113- if ( ! jupyterUp ) {
114- console . log ( "jupyter has not come up after 3 seconds, waiting 3 more" ) ;
115- await sleep ( 3000 ) ;
116-
117- if ( ! jupyterUp ) {
118- console . log ( "jupyter has not come up after 6 seconds, bailing" ) ;
119- process . exit ( 1 ) ;
120- }
121- }
40+ console . log ( `Created bucket ${ bucketName } ` ) ;
12241
12342 const originalNotebook = {
12443 cells : [
@@ -153,47 +72,18 @@ const main = async () => {
15372 nbformat_minor : 2
15473 } ;
15574
156- const xhr = await ajax ( {
157- url : `${ jupyterEndpoint } /api/contents/ci-local-writeout.ipynb` ,
158- responseType : "json" ,
159- createXHR : ( ) => new XMLHttpRequest ( ) ,
160- method : "PUT" ,
161- body : {
162- type : "notebook" ,
163- content : originalNotebook
164- } ,
165- headers : {
166- "Content-Type" : "application/json" ,
167- Authorization : `token ${ jupyterToken } `
168- }
169- } ) . toPromise ( ) ;
75+ jupyterServer . writeNotebook ( "ci-local-writeout.ipynb" , originalNotebook ) ;
17076
17177 // Wait for minio to have the notebook
17278 // Future iterations of this script should poll to get the notebook
17379 await sleep ( 1000 ) ;
17480
175- jupyter . kill ( ) ;
81+ jupyterServer . shutdown ( ) ;
17682
177- //// Check the notebook we placed on S3
178- const rawNotebook = await new Promise ( ( resolve , reject ) =>
179- minioClient . getObject (
180- bucketName ,
181- "ci-workspace/ci-local-writeout.ipynb" ,
182- ( err , dataStream ) => {
183- if ( err ) {
184- console . error ( "wat" ) ;
185- reject ( err ) ;
186- return ;
187- }
188-
189- const chunks = [ ] ;
190- dataStream . on ( "data" , chunk => chunks . push ( chunk ) ) ;
191- dataStream . on ( "error" , reject ) ;
192- dataStream . on ( "end" , ( ) => {
193- resolve ( Buffer . concat ( chunks ) . toString ( "utf8" ) ) ;
194- } ) ;
195- }
196- )
83+ /***** Check notebook from S3 *****/
84+ const rawNotebook = await s3Client . getObject (
85+ bucketName ,
86+ "ci-workspace/ci-local-writeout.ipynb"
19787 ) ;
19888
19989 const notebook = JSON . parse ( rawNotebook ) ;
@@ -208,7 +98,7 @@ const main = async () => {
20898
20999 console . log ( "Notebook on S3 matches what we sent" ) ;
210100
211- //// Check the notebook we placed on Disk
101+ /***** Check notebook from Disk *****/
212102 const diskNotebook = await new Promise ( ( resolve , reject ) =>
213103 fs . readFile (
214104 path . join ( __dirname , "ci-local-writeout.ipynb" ) ,
0 commit comments