@@ -20,21 +20,23 @@ function fib(n) {
2020 * limitations under the License.
2121 */
2222
23- process . env . GCLOUD_DEBUG_LOGLEVEL = 3 ;
23+ process . env . GCLOUD_DEBUG_LOGLEVEL = 2 ;
2424
2525var assert = require ( 'assert' ) ;
2626var util = require ( 'util' ) ;
2727var GoogleAuth = require ( 'google-auth-library' ) ;
28- var agent = require ( '../..' ) ;
2928var _ = require ( 'lodash' ) ; // for _.find. Can't use ES6 yet.
3029var Q = require ( 'q' ) ;
30+ var cluster = require ( 'cluster' ) ;
3131
3232var DEBUG_API = 'https://clouddebugger.googleapis.com/v2/debugger' ;
3333var SCOPES = [
3434 'https://www.googleapis.com/auth/cloud-platform' ,
3535 'https://www.googleapis.com/auth/cloud_debugger' ,
3636 ] ;
3737
38+ var agent ;
39+
3840function apiRequest ( authClient , url , method , body ) {
3941 method = method || 'GET' ;
4042
@@ -54,14 +56,9 @@ function apiRequest(authClient, url, method, body) {
5456 return deferred . promise ;
5557}
5658
57- module . exports . runTest = function runTest ( ) {
59+ function runTest ( ) {
5860 Q . delay ( 10 * 1000 ) . then ( function ( ) {
59- assert . ok ( agent . private_ , 'debuglet has initialized' ) ;
60- var debuglet = agent . private_ ;
61- assert . ok ( debuglet . debugletApi_ , 'debuglet api is active' ) ;
62- var api = debuglet . debugletApi_ ;
63- assert . ok ( api . uid_ , 'debuglet provided unique id' ) ;
64- assert . ok ( api . debuggeeId_ , 'debuglet has registered' ) ;
61+ var api = agent . private_ . debugletApi_ ;
6562
6663 var debuggee = api . debuggeeId_ ;
6764 var project = api . project_ ;
@@ -159,11 +156,9 @@ module.exports.runTest = function runTest() {
159156 assert . ok ( result . breakpoint ) ;
160157 assert . ok ( result . debuggee ) ;
161158 console . log ( '-- waiting a bit before running fib' ) ;
162- return Q . delay ( 20 * 1000 ) . then ( function ( ) { return result ; } ) ;
159+ return Q . delay ( 10 * 1000 ) . then ( function ( ) { return result ; } ) ;
163160 } )
164161 . then ( function ( result ) {
165- console . log ( '-- Running fib' ) ;
166- fib ( 12 ) ;
167162 console . log ( '-- waiting before checking if the breakpoint was hit' ) ;
168163 return Q . delay ( 10 * 1000 ) . then ( function ( ) { return result ; } ) ;
169164 } )
@@ -198,9 +193,29 @@ module.exports.runTest = function runTest() {
198193 } ) . catch ( function ( e ) {
199194 console . error ( e ) ;
200195 } ) ;
201- } ;
196+ }
202197
203- // check if we were launched directly, if so run the test
204- if ( ! module . parent ) {
205- module . exports . runTest ( ) ;
198+ if ( cluster . isMaster ) {
199+ var handler = function ( m ) {
200+ assert . ok ( m . private_ , 'debuglet has initialized' ) ;
201+ var debuglet = m . private_ ;
202+ assert . ok ( debuglet . debugletApi_ , 'debuglet api is active' ) ;
203+ var api = debuglet . debugletApi_ ;
204+ assert . ok ( api . uid_ , 'debuglet provided unique id' ) ;
205+ assert . ok ( api . debuggeeId_ , 'debuglet has registered' ) ;
206+ if ( agent ) {
207+ assert . equal ( agent . private_ . debugletApi_ . uid_ , api . uid_ ) ;
208+ assert . equal ( agent . private_ . debugletApi_ . debuggeeId_ , api . debuggeeId_ ) ;
209+ } else {
210+ agent = m ;
211+ }
212+ } ;
213+ for ( var i = 0 ; i < 3 ; i ++ ) {
214+ cluster . fork ( ) . on ( 'message' , handler ) ;
215+ }
216+ runTest ( ) ;
217+ } else {
218+ var agent = require ( '../..' ) ;
219+ setTimeout ( process . send . bind ( process , agent ) , 7000 ) ;
220+ setInterval ( fib . bind ( null , 12 ) , 2000 ) ;
206221}
0 commit comments