6917acdf0d73b2e4900945388d8ac59bc70f3381
[platform/upstream/iotjs.git] / tools / test / run_pass / test_timers.js
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16
17 var assert = require('assert');
18
19
20 var timerACnt = 0;
21 var timerBCnt = 0;
22 var timerSequence = '';
23
24 var timerA = setTimeout(function() {
25   timerSequence += 'A';
26   timerACnt++;
27 }, 1000);
28
29 var timerB = setInterval(function() {
30   timerSequence += 'B';
31   timerBCnt++;
32   if (timerBCnt > 5) {
33     clearInterval(timerB);
34   }
35 }, 300);
36
37 process.on('exit', function(code) {
38   assert.equal(code, 0);
39   assert.equal(timerACnt, 1);
40   assert.equal(timerBCnt, 6);
41   assert.equal(timerSequence.length, 7);
42 });