• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nicholaswmin / dyno / 10395877569

14 Aug 2024 10:24PM UTC coverage: 94.636% (-0.04%) from 94.671%
10395877569

Pull #8

github

web-flow
Merge e9e891e86 into 3631fa0e3
Pull Request #8: refactor: tweaks

505 of 559 branches covered (90.34%)

Branch coverage included in aggregate %.

27 of 28 new or added lines in 7 files covered. (96.43%)

2 existing lines in 1 file now uncovered.

2212 of 2312 relevant lines covered (95.67%)

343.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.87
/index.js
1
import os from 'node:os'
31✔
2
import timer from 'timers/promises'
31✔
3
import prompt from './src/prompt/index.js'
31✔
4
import threadpool from './src/threadpool/index.js'
31✔
5
import runTask from './src/run-task/index.js'
31✔
6
import Uptimer from './src/uptimer/index.js'
31✔
7
import Scheduler from './src/scheduler/index.js'
31✔
8
import { MetricsCollector } from './src/metrics/index.js'
31✔
9

31✔
10
const dyno = async (taskFn, { 
31✔
11
  parameters, 
12✔
12
  onTick = () => {},
12✔
13
  before = async () => {},
12✔
14
  after  = async () => {}
12✔
15
}) => {
12✔
16
  const isPrimary = !Object.hasOwn(process.env, 'THREAD_INDEX')
12✔
17

12✔
18
  if (isPrimary) {  
12✔
19
    await before(parameters)
12✔
20

12✔
21
    parameters = await prompt(parameters, {
12✔
22
      disabled: ['test'].includes(process.env.NODE_ENV?.toLowerCase()),
12✔
23
      defaults: {
12✔
24
        cyclesPerSecond: 50,
12✔
25
        durationMs: 5 * 1000,
12✔
26
        threads: os.availableParallelism()
12✔
27
      }
12✔
28
    })
12✔
29

12✔
30
    const abortctrl = new AbortController()
12✔
31
    const collector = new MetricsCollector()
12✔
32
    const scheduler = new Scheduler(parameters)
12✔
33
    const uptimer = new Uptimer()
12✔
34
    const threads = await threadpool.fork(
12✔
35
      // @TODO document the following line intention
12✔
36
      typeof taskFn === 'function' ? process.argv[1] : taskFn, { 
12!
37
      threads: parameters.threads,
12✔
38
      parameters: parameters
12✔
39
    })
12✔
40
    
12✔
41
    process.start()
12✔
42
    scheduler.start(threads)
12✔
43
    collector.start(threads, onTick.bind(this))
12✔
44
    uptimer.start()
12✔
45

12✔
46
    try {
12✔
47
      await Promise.race([
12✔
48
        threadpool.watch(threads, abortctrl),
12✔
49
        timer.setTimeout(parameters.durationMs, null, abortctrl)
12✔
50
      ])
12✔
51
    } finally {
12✔
52
      await after(parameters, collector.result())
12✔
53

12✔
54
      abortctrl.abort()
12✔
55
      collector.stop()
12✔
56
      uptimer.stop()
12✔
57
      scheduler.stop()
12✔
58
  
12✔
59
      await threadpool.disconnect(threads)
12✔
60
    }
11✔
61
  
9✔
62
    return collector.result()
9✔
63
  }
9!
UNCOV
64
  
×
NEW
UNCOV
65
  return runTask(taskFn)
×
66
}
12✔
67

31✔
68
export { dyno, runTask as task }
31✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc