File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -65,13 +65,14 @@ before_install:
65
65
66
66
# Setup environment
67
67
- " export MYSQL_DATABASE=node_mysql"
68
+ - " export MYSQL_HOST=localhost"
68
69
- " export MYSQL_PORT=$(node tool/free-port.js)"
69
70
- " export MYSQL_USER=root"
70
71
71
72
install :
72
73
- " docker run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=$MYSQL_DATABASE -p $MYSQL_PORT:3306 $DOCKER_MYSQL_TYPE:$DOCKER_MYSQL_VERSION"
73
74
- " npm install"
74
- - " docker run --link mysql:db -e CHECK_PORT=3306 -e CHECK_HOST=db giorgos/takis "
75
+ - " node tool/wait- mysql.js $MYSQL_PORT $MYSQL_HOST "
75
76
76
77
before_script :
77
78
- " docker --version"
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ environment:
4
4
MYSQL_USER : root
5
5
MYSQL_PASSWORD : Password12!
6
6
MYSQL_PATH : C:\Program Files\MySQL\MySQL Server 5.7
7
+ MYSQL_PORT : 3306
7
8
8
9
matrix :
9
10
- nodejs_version : " 0.8"
@@ -41,6 +42,7 @@ build: off
41
42
42
43
before_test :
43
44
- SET PATH=%MYSQL_PATH%\bin;%PATH%
45
+ - node tool/wait-mysql.js %MYSQL_PORT% %MYSQL_HOST%
44
46
- mysqladmin --host=%MYSQL_HOST% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% create %MYSQL_DATABASE%
45
47
46
48
test_script :
Original file line number Diff line number Diff line change
1
+ var Net = require ( 'net' ) ;
2
+
3
+ var CHECK_INTERVAL_MS = 200 ;
4
+ var CHECK_TIMEOUT = 120000 ;
5
+ var TCP_TIMEOUT = 1000 ;
6
+
7
+ process . nextTick ( run ) ;
8
+
9
+ function check ( host , port , callback ) {
10
+ var socket = Net . createConnection ( port , host ) ;
11
+ var timer = setTimeout ( function ( ) {
12
+ socket . destroy ( ) ;
13
+ callback ( false ) ;
14
+ } , TCP_TIMEOUT ) ;
15
+
16
+ socket . once ( 'data' , function ( ) {
17
+ clearTimeout ( timer ) ;
18
+ socket . destroy ( ) ;
19
+ callback ( true ) ;
20
+ } ) ;
21
+
22
+ socket . on ( 'error' , function ( ) {
23
+ clearTimeout ( timer ) ;
24
+ callback ( false ) ;
25
+ } ) ;
26
+ }
27
+
28
+ function run ( ) {
29
+ var host = process . argv [ 3 ] || 'localhost' ;
30
+ var port = Number ( process . argv [ 2 ] ) ;
31
+
32
+ function next ( ) {
33
+ check ( host , port , function ( connected ) {
34
+ if ( connected ) {
35
+ console . log ( 'connected to %s:%d' , host , port ) ;
36
+ process . exit ( 0 ) ;
37
+ } else {
38
+ setTimeout ( next , CHECK_INTERVAL_MS ) ;
39
+ }
40
+ } ) ;
41
+ }
42
+
43
+ setTimeout ( function ( ) {
44
+ console . error ( 'timeout waiting for %s:%d' , host , port ) ;
45
+ process . exit ( 1 ) ;
46
+ } , CHECK_TIMEOUT ) ;
47
+
48
+ next ( ) ;
49
+ }
You can’t perform that action at this time.
0 commit comments