Produced by Araxis Merge on 10/3/2017 11:16:01 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | ehmp.zip\ehmp\ehmp\product\production\vx-sync\tests\integrationtests\framework | handler-test-framework.js | Mon Jul 10 17:46:22 2017 UTC |
| 2 | ehmp.zip\ehmp\ehmp\product\production\vx-sync\tests\integrationtests\framework | handler-test-framework.js | Tue Oct 3 12:44:13 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 992 |
| Changed | 2 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | 'use stric t'; | |
| 2 | ||
| 3 | require('. ./../../en v-setup'); | |
| 4 | ||
| 5 | var util = require(' util'); | |
| 6 | var _ = re quire('und erscore'); | |
| 7 | var async = require( 'async'); | |
| 8 | var reques t = requir e('request '); | |
| 9 | ||
| 10 | var val = require(gl obal.VX_UT ILS + 'obj ect-utils' ).getPrope rty; | |
| 11 | var queueC onfig = re quire(glob al.VX_JOBF RAMEWORK). QueueConfi g; | |
| 12 | var grabJo bs = requi re('./job- grabber'); | |
| 13 | var Publis herRouter = require( global.VX_ JOBFRAMEWO RK).Publis herRouter; | |
| 14 | ||
| 15 | var counte r = 0; | |
| 16 | /* | |
| 17 | Note that using this framework only test s that whe n called, the handle r creates | |
| 18 | the correc t number a nd types o f jobs and verifies that they are all pu shed onto | |
| 19 | the Beanst alk tube. You should ensure th at the res ultant job s created contain | |
| 20 | the correc t values v ia unit te sts for yo ur handler . | |
| 21 | ||
| 22 | handler: t he handler function you are te sting. Thi s function should ha ve the | |
| 23 | signature: handler(l ogger, con fig, envir onment, jo b, callbac k) | |
| 24 | ||
| 25 | logger: th e bunyan l ogger to u se. Note t hat the du mmy-logger will also work. | |
| 26 | ||
| 27 | config: a config obj ect which should be pre-loaded with any properties necessary | |
| 28 | for your h andler. No te that yo u should N OT include the beans talk publi sher | |
| 29 | properties , but may include a beanstalkC onfig obje ct for the queue-con fig factor y, | |
| 30 | or if none is provid ed the def ault will be used. | |
| 31 | ||
| 32 | host: the server whe re beansta lk is runn ing. This will usual ly be ' IP ' or '127. 0.0.1'. | |
| 33 | ||
| 34 | port: the port on wh ich beanst alk is run ning. This will usua lly be PORT . | |
| 35 | ||
| 36 | tubePrefix : the tube Prefix pre pended to the type o f the job parameter which is u sed | |
| 37 | to generat e the tube name. | |
| 38 | ||
| 39 | job: the j ob instanc e to use w hen callin g the hand ler. | |
| 40 | ||
| 41 | jobTypes: the expect ed resulti ng jobType s. This ca n be eithe r an array , a single | |
| 42 | string, or an object . The fram ework will verify th at the han dler creat es one eac h of these types | |
| 43 | of jobs. N OTE: By de fault the framework will check that the exact numb er of inst ances of e ach given job type i s created. | |
| 44 | To by pass this strict che ck, pass a n object i nto jobTyp es like so : | |
| 45 | { | |
| 46 | jobTypes: [<array of job type strings>], | |
| 47 | ignoreTota lJobs: tru e | |
| 48 | } | |
| 49 | ||
| 50 | waitTimeou t: the tie mout in mi llis to wa it for the response from the h andler. De faults | |
| 51 | to 10000 ( 10 seconds ). | |
| 52 | */ | |
| 53 | function t estHandler (handler, logger, co nfig, envi ronment, h ost, port, tubePrefi x, job, jo bTypes, wa itTimeout, handlerCa llback) { | |
| 54 | logger .debug('ha ndler-test -framework .testHandl er() %s:%s from %s - > %s', hos t, port, j ob.type, j obTypes); | |
| 55 | ||
| 56 | waitTi meout = _. isNumber(w aitTimeout ) ? waitTi meout : 10 000; | |
| 57 | ||
| 58 | var ig noreTotalJ obs; | |
| 59 | ||
| 60 | if(_.i sString(jo bTypes)){ | |
| 61 | jo bTypes = [ jobTypes]; | |
| 62 | } else if(!_.isA rray(jobTy pes)){ | |
| 63 | ig noreTotalJ obs = jobT ypes.ignor eTotalJobs ; | |
| 64 | jo bTypes = j obTypes.jo bTypes; | |
| 65 | } | |
| 66 | ||
| 67 | counte r++; | |
| 68 | ||
| 69 | var be anstalkCon fig = getB eanstalkCo nfig(confi g, host, p ort, tubeP refix + '- ' + job.ty pe); | |
| 70 | update Tubenames( beanstalkC onfig); | |
| 71 | logger .debug(bea nstalkConf ig); | |
| 72 | ||
| 73 | var tu benames = getTubenam es(beansta lkConfig, jobTypes); | |
| 74 | ||
| 75 | var de scribeText = util.fo rmat('test s handler for "%s" j ob on tube (s) "%s"', job && jo b.type, tu benames); | |
| 76 | var it Text = uti l.format(' verify the correct % s jobs are put on tu be(s) "%s" for jobTy pe "%s", j obs: ', _. size(jobTy pes), tube names, job && job.ty pe); | |
| 77 | itText = _.reduc e(jobTypes , function (memo, job Type) { | |
| 78 | re turn memo + '\n\t\t" ' + jobTyp e + '"'; | |
| 79 | }, itT ext); | |
| 80 | ||
| 81 | descri be(describ eText, fun ction() { | |
| 82 | va r callback ; | |
| 83 | va r jobStatu sUpdater; | |
| 84 | va r called; | |
| 85 | va r calledEr ror; | |
| 86 | va r calledRe sult; | |
| 87 | ||
| 88 | be foreEach(f unction() { | |
| 89 | logger.d ebug('hand ler-test-f ramework: **** Enter ed beforeE ach.'); | |
| 90 | called = false; | |
| 91 | ||
| 92 | config.b eanstalk = beanstalk Config; | |
| 93 | ||
| 94 | jobStatu sUpdater = { | |
| 95 | crea teJobStatu s: functio n(job, cal lback) { | |
| 96 | callback() ; | |
| 97 | }, | |
| 98 | erro rJobStatus : function (job, erro r, callbac k) { | |
| 99 | callback() ; | |
| 100 | } | |
| 101 | }; | |
| 102 | ||
| 103 | if (!env ironment) { | |
| 104 | envi ronment = { | |
| 105 | publisherR outer: new Publisher Router(log ger, confi g, logger, jobStatus Updater), | |
| 106 | metrics: l ogger | |
| 107 | }; | |
| 108 | } else i f (!enviro nment.publ isherRoute r) { | |
| 109 | if ( !environme nt.jobStat usUpdater) { | |
| 110 | environmen t.jobStatu sUpdater = jobStatus Updater; | |
| 111 | } | |
| 112 | ||
| 113 | envi ronment.pu blisherRou ter = new PublisherR outer(logg er, config , logger, environmen t.jobStatu sUpdater); | |
| 114 | } | |
| 115 | ||
| 116 | callback = functio n(error, r esult) { | |
| 117 | call ed = true; | |
| 118 | call edError = error; | |
| 119 | call edResult = result; | |
| 120 | }; | |
| 121 | }) ; | |
| 122 | ||
| 123 | af terEach(fu nction() { | |
| 124 | environm ent.publis herRouter. close(); | |
| 125 | ||
| 126 | var clea red = fals e; | |
| 127 | ||
| 128 | grabJobs (logger, h ost, port, tubenames , 0, funct ion() { | |
| 129 | clea red = true ; | |
| 130 | logg er.debug(' handler-te st-framewo rk: **** c learTube c allback wa s called.' ); | |
| 131 | }); | |
| 132 | ||
| 133 | clearTub es(logger, host, por t, tubenam es, functi on() { | |
| 134 | clea red = true ; | |
| 135 | logg er.debug(' handler-te st-framewo rk: **** c learTube c allback wa s called.' ); | |
| 136 | }); | |
| 137 | ||
| 138 | waitsFor (function( ) { | |
| 139 | retu rn cleared ; | |
| 140 | }, 'clea r jobs tim ed out', w aitTimeout ); | |
| 141 | ||
| 142 | runs(fun ction() { | |
| 143 | logg er.debug(' handler-te st-framewo rk: **** t est comple te.'); | |
| 144 | }); | |
| 145 | }) ; | |
| 146 | ||
| 147 | it (itText, f unction() { | |
| 148 | logger.d ebug('hand ler-test-f ramework: **** Initi ating call to handle r.'); | |
| 149 | handler( logger, co nfig, envi ronment, j ob, functi on(error) { | |
| 150 | if ( error) { | |
| 151 | calledErro r = error; | |
| 152 | called = t rue; | |
| 153 | return; | |
| 154 | } | |
| 155 | ||
| 156 | logg er.debug(' handler-te st-framewo rk: **** I nitiating call to gr abJobs.'); | |
| 157 | grab Jobs(logge r, host, p ort, tuben ames, 2, f unction(er ror, resul t) { | |
| 158 | calledErro r = error; | |
| 159 | calledResu lt = resul t; | |
| 160 | called = t rue; | |
| 161 | }); | |
| 162 | }, funct ion() {}); | |
| 163 | ||
| 164 | waitsFor (function( ) { | |
| 165 | retu rn called; | |
| 166 | }, 'bean stalk jobs returned' , waitTime out); | |
| 167 | ||
| 168 | runs(fun ction() { | |
| 169 | expe ct(calledE rror).toBe Null(); | |
| 170 | ||
| 171 | var resultJobT ypes = _.c hain(calle dResult).m ap(functio n(result) { | |
| 172 | return res ult.jobs; | |
| 173 | }).f latten().p luck('type ').value() ; | |
| 174 | ||
| 175 | logg er.debug(' resultJobT ypes %s', resultJobT ypes); | |
| 176 | ||
| 177 | if(! ignoreTota lJobs){ | |
| 178 | expect(val (resultJob Types, 'le ngth')).to Be(jobType s.length); | |
| 179 | } | |
| 180 | ||
| 181 | _.ea ch(jobType s, functio n(match) { | |
| 182 | expect(res ultJobType s).toConta in(match); | |
| 183 | }); | |
| 184 | // h andler pos t-publish callback | |
| 185 | if ( _.isFuncti on(handler Callback)) { | |
| 186 | handlerCal lback(call edResult); | |
| 187 | } | |
| 188 | }); | |
| 189 | }) ; | |
| 190 | }); | |
| 191 | } | |
| 192 | ||
| 193 | function g etBeanstal kConfig(co nfig, host , port, de faultTuben ame) { | |
| 194 | var be anstalkCon fig; | |
| 195 | ||
| 196 | if (!_ .isUndefin ed(config. beanstalkC onfig)) { | |
| 197 | // console.l og('using handler in tegration test confi g'); | |
| 198 | // the handl er framewo rk is resp onsible fo r configur ing the be anstalk tu bes, but t he queueCo nfig modul e's | |
| 199 | // factory m ethod for the beanst alk config can be ca lled on a customized outline o r use the default | |
| 200 | co nfig.beans talkConfig .repoDefau lts.tubena me = defau ltTubename ; | |
| 201 | be anstalkCon fig = queu eConfig.cr eateFullBe anstalkCon fig(config .beanstalk Config); | |
| 202 | } else { | |
| 203 | // console.l og('using default te st config' ); | |
| 204 | be anstalkCon fig = queu eConfig.cr eateFullBe anstalkCon fig({ | |
| 205 | repoUniv ersal: { | |
| 206 | prio rity: 10, | |
| 207 | dela y: 0, | |
| 208 | ttr: 60, | |
| 209 | time out: 10, | |
| 210 | init Millis: 10 00, | |
| 211 | maxM illis: 150 00, | |
| 212 | incM illis: 100 0 | |
| 213 | }, | |
| 214 | repoDefa ults: { | |
| 215 | host : host, | |
| 216 | port : port, | |
| 217 | tube name: defa ultTubenam e, | |
| 218 | tube Prefix: 'v xs-', | |
| 219 | jobT ypeForTube : false | |
| 220 | }, | |
| 221 | jobTypes : { | |
| 222 | 'ent erprise-sy nc-request ': {}, | |
| 223 | 'vis ta-operati onal-subsc ribe-reque st': {}, | |
| 224 | 'res ync-reques t': {}, | |
| 225 | ||
| 226 | 'vis ta-9E7A-su bscribe-re quest': {} , | |
| 227 | 'vis ta-C877-su bscribe-re quest': {} , | |
| 228 | ||
| 229 | 'vle r-sync-req uest': {}, | |
| 230 | 'pgd -sync-requ est': {}, | |
| 231 | 'hdr -sync-requ est': {}, | |
| 232 | 'jme adows-sync -request': {}, | |
| 233 | ||
| 234 | 'hdr -xform-vpr ': {}, | |
| 235 | 'vle r-xform-vp r': {}, | |
| 236 | 'pgd -xform-vpr ': {}, | |
| 237 | ||
| 238 | 'jme adows-sync -allergy-r equest': { }, | |
| 239 | 'jme adows-sync -appointme nt-request ': {}, | |
| 240 | 'jme adows-sync -consult-r equest': { }, | |
| 241 | 'jme adows-sync -demograph ics-reques t': {}, | |
| 242 | 'jme adows-sync -discharge Summary-re quest': {} , | |
| 243 | 'jme adows-sync -encounter -request': {}, | |
| 244 | 'jme adows-sync -immunizat ion-reques t': {}, | |
| 245 | 'jme adows-sync -lab-reque st': {}, | |
| 246 | 'jme adows-sync -medicatio n-request' : {}, | |
| 247 | 'jme adows-sync -note-requ est': {}, | |
| 248 | 'jme adows-sync -order-req uest': {}, | |
| 249 | 'jme adows-sync -problem-r equest': { }, | |
| 250 | 'jme adows-sync -progressN ote-reques t': {}, | |
| 251 | 'jme adows-sync -radiology -request': {}, | |
| 252 | 'jme adows-sync -vital-req uest': {}, | |
| 253 | ||
| 254 | 'hdr -sync-alle rgy-reques t': {}, | |
| 255 | 'hdr -sync-appo intment-re quest': {} , | |
| 256 | 'hdr -sync-cons ult-reques t': {}, | |
| 257 | 'hdr -sync-cpt- request': {}, | |
| 258 | 'hdr -sync-docu ment-reque st': {}, | |
| 259 | 'hdr -sync-educ ation-requ est': {}, | |
| 260 | 'hdr -sync-exam -request': {}, | |
| 261 | 'hdr -sync-imag e-request' : {}, | |
| 262 | 'hdr -sync-immu nization-r equest': { }, | |
| 263 | 'hdr -sync-lab- request': {}, | |
| 264 | 'hdr -sync-mh-r equest': { }, | |
| 265 | 'hdr -sync-orde r-request' : {}, | |
| 266 | 'hdr -sync-pov- request': {}, | |
| 267 | 'hdr -sync-prob lem-reques t': {}, | |
| 268 | 'hdr -sync-proc edure-requ est': {}, | |
| 269 | 'hdr -sync-skin -request': {}, | |
| 270 | 'hdr -sync-surg ery-reques t': {}, | |
| 271 | 'hdr -sync-visi t-request' : {}, | |
| 272 | 'hdr -sync-vita l-request' : {}, | |
| 273 | ||
| 274 | ||
| 275 | 'jme adows-xfor m-allergy- vpr': {}, | |
| 276 | 'jme adows-xfor m-appointm ent-vpr': {}, | |
| 277 | 'jme adows-xfor m-consult- vpr': {}, | |
| 278 | 'jme adows-xfor m-demograp hics-vpr': {}, | |
| 279 | 'jme adows-xfor m-discharg eSummary-v pr': {}, | |
| 280 | 'jme adows-xfor m-encounte r-vpr': {} , | |
| 281 | 'jme adows-xfor m-immuniza tion-vpr': {}, | |
| 282 | 'jme adows-xfor m-lab-vpr' : {}, | |
| 283 | 'jme adows-xfor m-medicati on-vpr': { }, | |
| 284 | 'jme adows-xfor m-note-vpr ': {}, | |
| 285 | 'jme adows-xfor m-order-vp r': {}, | |
| 286 | 'jme adows-xfor m-problem- vpr': {}, | |
| 287 | 'jme adows-xfor m-progress Note-vpr': {}, | |
| 288 | 'jme adows-xfor m-radiolog y-vpr': {} , | |
| 289 | 'jme adows-xfor m-vital-vp r': {}, | |
| 290 | ||
| 291 | 'hdr -xform-all ergy-vpr': {}, | |
| 292 | 'hdr -xform-app ointment-v pr': {}, | |
| 293 | 'hdr -xform-con sult-vpr': {}, | |
| 294 | 'hdr -xform-cpt -vpr': {}, | |
| 295 | 'hdr -xform-doc ument-vpr' : {}, | |
| 296 | 'hdr -xform-edu cation-vpr ': {}, | |
| 297 | 'hdr -xform-exa m-vpr': {} , | |
| 298 | 'hdr -xform-ima ge-vpr': { }, | |
| 299 | 'hdr -xform-imm unization- vpr': {}, | |
| 300 | 'hdr -xform-lab -vpr': {}, | |
| 301 | 'hdr -xform-mh- vpr': {}, | |
| 302 | 'hdr -xform-ord er-vpr': { }, | |
| 303 | 'hdr -xform-pov -vpr': {}, | |
| 304 | 'hdr -xform-pro blem-vpr': {}, | |
| 305 | 'hdr -xform-pro cedure-vpr ': {}, | |
| 306 | 'hdr -xform-ski n-vpr': {} , | |
| 307 | 'hdr -xform-sur gery-vpr': {}, | |
| 308 | 'hdr -xform-vis it-vpr': { }, | |
| 309 | 'hdr -xform-vit al-vpr': { }, | |
| 310 | ||
| 311 | 'jme adows-pdf- document-t ransform': {}, | |
| 312 | 'jme adows-cda- document-c onversion' : {}, | |
| 313 | 'jme adows-docu ment-retri eval': {}, | |
| 314 | ||
| 315 | 'rec ord-enrich ment': {}, | |
| 316 | 'sto re-record' : {}, | |
| 317 | 'eve nt-priorit ization-re quest': {} , | |
| 318 | 'ope rational-s tore-recor d': {}, | |
| 319 | 'pub lish-data- change-eve nt': {}, | |
| 320 | 'pat ient-data- state-chec ker': {} | |
| 321 | } | |
| 322 | }) ; | |
| 323 | } | |
| 324 | ||
| 325 | return beanstalk Config; | |
| 326 | } | |
| 327 | ||
| 328 | function u pdateTuben ames(beans talkConfig ) { | |
| 329 | beanst alkConfig. repoDefaul ts.tubenam e = beanst alkConfig. repoDefaul ts.tubenam e + '-' + counter; | |
| 330 | ||
| 331 | _.each (beanstalk Config.job Types, fun ction(jobT ype) { | |
| 332 | jo bType.tube name = job Type.tuben ame + '-' + counter; | |
| 333 | }); | |
| 334 | } | |
| 335 | ||
| 336 | function g etTubename s(beanstal kConfig, j obTypes) { | |
| 337 | var tu benames = _.chain(jo bTypes) | |
| 338 | .m ap(functio n(jobType) { | |
| 339 | if (!_.i sUndefined (beanstalk Config.job Types[jobT ype]) && _ .isArray(b eanstalkCo nfig.jobTy pes[jobTyp e].tubeDet ails)) { | |
| 340 | var baseTubena me = beans talkConfig .jobTypes[ jobType].t ubename; | |
| 341 | retu rn _.map(_ .range(bea nstalkConf ig.jobType s[jobType] .tubeDetai ls.length) , function (num) { | |
| 342 | return bas eTubename + (num + 1 ); | |
| 343 | }); | |
| 344 | } else { | |
| 345 | retu rn beansta lkConfig.j obTypes[jo bType] ? b eanstalkCo nfig.jobTy pes[jobTyp e].tubenam e : undefi ned; | |
| 346 | } | |
| 347 | }) | |
| 348 | .c ompact() | |
| 349 | .f latten() | |
| 350 | .u niq() | |
| 351 | .v alue(); | |
| 352 | ||
| 353 | return tubenames .length > 0 ? tubena mes : [bea nstalkConf ig.repoDef aults.tube name]; | |
| 354 | } | |
| 355 | ||
| 356 | function c learTubes( logger, ho st, port, tubenames, callback) { | |
| 357 | logger .debug('ha ndler-test -framework : **** Ent ered clear Tube.'); | |
| 358 | ||
| 359 | var ca lled = fal se; | |
| 360 | var ca lledError; | |
| 361 | ||
| 362 | grabJo bs(logger, host, por t, tubenam es, 0, fun ction(erro r) { | |
| 363 | ca lled = tru e; | |
| 364 | ca lledError = error; | |
| 365 | }); | |
| 366 | ||
| 367 | waitsF or(functio n() { | |
| 368 | re turn calle d; | |
| 369 | }, 'sh ould be ca lled', 200 0); | |
| 370 | ||
| 371 | runs(f unction() { | |
| 372 | ex pect(calle dError).to BeNull(); | |
| 373 | lo gger.debug ('handler- test-frame work: **** Exiting c learTube.' ); | |
| 374 | re turn callb ack(); | |
| 375 | }); | |
| 376 | } | |
| 377 | ||
| 378 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 379 | // Helper function f or syncAnd WaitForPat ient | |
| 380 | // This fu nction che cks the sy nc status to see if there is n othing in progress a nd there a re no | |
| 381 | // open jo bs. If th at is the case, it w ill set sy ncIsComple te to true . | |
| 382 | // | |
| 383 | // callbac k: The fun ction to c all when t he check i s done. | |
| 384 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 385 | function c heckSyncCo mplete(log , config, pid, share dSyncStats , callback ) { | |
| 386 | log.de bug('handl er-test-fr amework.ch eckSyncCom plete: Ent ered metho d.'); | |
| 387 | var sy ncStatusCa llComplete = false; | |
| 388 | var sy ncStatusCa llError; | |
| 389 | var sy ncStatusCa llResponse ; | |
| 390 | runs(f unction() { | |
| 391 | va r options = { | |
| 392 | url: con fig.syncRe questApi.p rotocol + '://' + co nfig.syncR equestApi. host + ':' + config. syncReques tApi.port + config.s yncRequest Api.patien tStatusPat h + '?pid= ' + pid, | |
| 393 | method: 'GET' | |
| 394 | }; | |
| 395 | ||
| 396 | sh aredSyncSt ats.syncSt atusCalled Counter++; | |
| 397 | lo g.debug('h andler-tes t-framewor k.checkSyn cComplete: Retrievin g status: syncStatus CalledCoun ter: %s; o ptions: %j ', sharedS yncStats.s yncStatusC alledCount er, option s); | |
| 398 | re quest.get( options, f unction(er ror, respo nse, body) { | |
| 399 | log.debu g('handler -test-fram ework.chec kSyncCompl ete: Retri eving stat us - Call back calle d: error: %j, respon se: %j, bo dy: %j', e rror, resp onse, body ); | |
| 400 | expect(r esponse).t oBeTruthy( ); | |
| 401 | expect(v al(respons e, 'status Code')).to Be(200); | |
| 402 | expect(b ody).toBeT ruthy(); | |
| 403 | ||
| 404 | var sync StatusData ; | |
| 405 | try { | |
| 406 | sync StatusData = JSON.pa rse(body); | |
| 407 | } catch (parseErro r) {} | |
| 408 | ||
| 409 | log.debu g('handler -test-fram ework.chec kSyncCompl ete: Retri eving stat us - Call back calle d: syncSta tusData: % j', syncSt atusData); | |
| 410 | expect(s yncStatusD ata).toBeT ruthy(); | |
| 411 | if (sync StatusData && (_.isO bject(sync StatusData .syncStatu s)) && (_. isEmpty(sy ncStatusDa ta.syncSta tus.inProg ress)) && | |
| 412 | (_.i sArray(syn cStatusDat a.jobStatu s)) && (_. isEmpty(sy ncStatusDa ta.jobStat us))) { | |
| 413 | shar edSyncStat s.syncIsCo mplete = t rue; | |
| 414 | } | |
| 415 | ||
| 416 | syncStat usCallErro r = error; | |
| 417 | syncStat usCallResp onse = res ponse; | |
| 418 | syncStat usCallComp lete = tru e; | |
| 419 | return c allback(); | |
| 420 | }) ; | |
| 421 | }); | |
| 422 | ||
| 423 | waitsF or(functio n() { | |
| 424 | re turn syncS tatusCallC omplete; | |
| 425 | }, 'Ti med out wa iting for syncReques t.', 10000 ); | |
| 426 | } | |
| 427 | ||
| 428 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 429 | // Helper function f or syncAnd WaitForPat ient | |
| 430 | // Returns the value of syncIs Complete. | |
| 431 | // | |
| 432 | // returns TRUE if t he sync is complete. False if it is not . | |
| 433 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 434 | function i sSyncCompl ete(log, s haredSyncS tats) { | |
| 435 | log.de bug('handl er-test-fr amework.is SyncComple te: Entere d method. syncIsCom plete: %j' , sharedSy ncStats.sy ncIsComple te); | |
| 436 | return sharedSyn cStats.syn cIsComplet e; | |
| 437 | } | |
| 438 | ||
| 439 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 440 | // Syncs t he provide d pid via the sync r equest end point and then | |
| 441 | // waits f or it to c omplete sy nc. | |
| 442 | // | |
| 443 | // Paramet ers | |
| 444 | // log: a bunyan log ger | |
| 445 | // config: configura tion objec t - should at least have the s yncRequest Api attrib utes popul ated | |
| 446 | // pid: th e pid of t he patient to sync | |
| 447 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 448 | function s yncAndWait ForPatient (log, conf ig, pid) { | |
| 449 | var sy ncRequestC omplete = false; | |
| 450 | var sy ncRequestE rror; | |
| 451 | var sy ncRequestR esponse; | |
| 452 | ||
| 453 | var sh aredSyncSt ats = { | |
| 454 | sy ncIsComple te: false, | |
| 455 | sy ncStatusCa lledCounte r: 0 | |
| 456 | }; | |
| 457 | ||
| 458 | runs(f unction() { | |
| 459 | va r options = { | |
| 460 | url: con fig.syncRe questApi.p rotocol + '://' + co nfig.syncR equestApi. host + ':' + config. syncReques tApi.port + config.s yncRequest Api.patien tSyncPath + '?pid=' + pid, | |
| 461 | method: 'GET' | |
| 462 | }; | |
| 463 | ||
| 464 | lo g.debug('h andler-tes t-framewor k: Sync Re quest. op tions: %j' , options) ; | |
| 465 | re quest.get( options, f unction(er ror, respo nse, body) { | |
| 466 | log.debu g('handler -test-fram ework: Syn c Request call back called. e rror: %j; response: %j, body: %j', error , response , body); | |
| 467 | syncRequ estError = error; | |
| 468 | syncRequ estRespons e = respon se; | |
| 469 | expect(v al(respons e, 'status Code')).to Be(202); | |
| 470 | syncRequ estComplet e = true; | |
| 471 | }) ; | |
| 472 | }); | |
| 473 | ||
| 474 | waitsF or(functio n() { | |
| 475 | re turn syncR equestComp lete; | |
| 476 | }, 'Ti med out wa iting for syncReques t.', 10000 ); | |
| 477 | ||
| 478 | // Nee d to wait for the sy nc to comp lete. | |
| 479 | //---- ---------- ---------- ---------- ------ | |
| 480 | runs(f unction() { | |
| 481 | lo g.debug('h andler-tes t-framewor k: Startin g async.do Whilst.'); | |
| 482 | as ync.doUnti l(checkSyn cComplete. bind(null, log, conf ig, pid, s haredSyncS tats), isS yncComplet e.bind(nul l, log, sh aredSyncSt ats), func tion(error ) { | |
| 483 | expect(e rror).toBe Falsy(); | |
| 484 | log.debu g('handler -test-fram ework: asy nc.doWhils t call bac k called. error: %j ', error); | |
| 485 | }) ; | |
| 486 | }); | |
| 487 | ||
| 488 | waitsF or(functio n() { | |
| 489 | re turn share dSyncStats .syncIsCom plete; | |
| 490 | }, 'Ti med out wa iting for sync to co mplete.', 60000); | |
| 491 | } | |
| 492 | ||
| 493 | module.exp orts.syncA ndWaitForP atient = s yncAndWait ForPatient ; | |
| 494 | module.exp orts.testH andler = t estHandler ; | |
| 495 | module.exp orts.updat eTubenames = updateT ubenames; | |
| 496 | module.exp orts.getBe anstalkCon fig = getB eanstalkCo nfig; | |
| 497 | module.exp orts.getTu benames = getTubenam es; | |
| 498 | module.exp orts.clear Tubes = cl earTubes; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.