1 |
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | const tymly = require('./../lib')
|
6 | const path = require('path')
|
7 | const expect = require('chai').expect
|
8 |
|
9 | describe('Shutdown services tests', function () {
|
10 | this.timeout(process.env.TIMEOUT || 5000)
|
11 | let tymlyService, testService3
|
12 |
|
13 | it('should boot up tymly with some plugins', (done) => {
|
14 | tymly.boot(
|
15 | {
|
16 | pluginPaths: [
|
17 | path.resolve(__dirname, './fixtures/plugins/test-services-plugin')
|
18 | ]
|
19 | },
|
20 | (err, tymlyServices) => {
|
21 | tymlyService = tymlyServices.tymly
|
22 | testService3 = tymlyServices.testService3
|
23 | done(err)
|
24 | }
|
25 | )
|
26 | })
|
27 |
|
28 | it('should show the boot order was correct', () => {
|
29 | expect(tymlyService.orderedServiceNames).to.eql(
|
30 | [
|
31 | 'tymly',
|
32 | 'timestamp',
|
33 | 'temp',
|
34 | 'inventory',
|
35 | 'caches',
|
36 | 'storage',
|
37 | 'functions',
|
38 | 'blueprintDocs',
|
39 | 'testService3',
|
40 | 'registry',
|
41 | 'categories',
|
42 | 'statebox',
|
43 | 'testService1',
|
44 | 'testService2',
|
45 | 'probe'
|
46 | ]
|
47 | )
|
48 | expect(testService3.bootOrder).to.eql(
|
49 | [
|
50 | 'testService3',
|
51 | 'testService1',
|
52 | 'testService2'
|
53 | ]
|
54 | )
|
55 | })
|
56 |
|
57 | it('try to boot without plugins without shutting down, expect failure', (done) => {
|
58 | tymly.boot(
|
59 | {},
|
60 | (err, tymlyServices) => {
|
61 | expect(err.length).to.eql(1)
|
62 | expect(err[0].name).to.eql('unknownService')
|
63 | done()
|
64 | }
|
65 | )
|
66 | })
|
67 |
|
68 | it('should shut down Tymly and plugins', async () => {
|
69 | await tymlyService.shutdown()
|
70 | })
|
71 |
|
72 | it('should show shutdown order was the reverse of boot', () => {
|
73 | expect(testService3.shutdownOrder).to.eql(
|
74 | [
|
75 | 'testService2',
|
76 | 'testService1',
|
77 | 'testService3'
|
78 | ]
|
79 | )
|
80 | })
|
81 |
|
82 | it('should successfully boot tymly without any plugins if nothing is being cached', (done) => {
|
83 | tymly.boot(
|
84 | {},
|
85 | (err, tymlyServices) => {
|
86 | tymlyService = tymlyServices.tymly
|
87 | done(err)
|
88 | }
|
89 | )
|
90 | })
|
91 |
|
92 | it('should shut down Tymly and plugins', async () => {
|
93 | await tymlyService.shutdown()
|
94 | })
|
95 | })
|