Skip to content

Commit

Permalink
fix: add timeout options when exec arp (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
howel52 authored and natterstefan committed May 13, 2019
1 parent be837cc commit 4403a8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const find = require('../src/index')
var cp = require('mz/child_process')

const TEN_MEGA_BYTE = 1024 * 1024 * 10
const ONE_MINUTE = 60 * 1000

describe('local-devices', () => {
const platforms = [
Expand Down Expand Up @@ -62,14 +63,14 @@ describe('local-devices', () => {
expect(result).toBeUndefined()
})

it('invokes cp.exec with maxBuffer of 10 MB, when invoking find without an ip', async () => {
it('invokes cp.exec with maxBuffer of 10 MB and a timeout of 1 minute, when invoking find without an ip', async () => {
await find()
expect(cp.exec).toHaveBeenCalledWith('arp -a', { 'maxBuffer': TEN_MEGA_BYTE })
expect(cp.exec).toHaveBeenCalledWith('arp -a', { 'maxBuffer': TEN_MEGA_BYTE, 'timeout': ONE_MINUTE })
})

it('invokes cp.exec with maxBuffer of 10 MB, when invoking find with a single ip', async () => {
it('invokes cp.exec with maxBuffer of 10 MB and a timeout of 1 minute, when invoking find with a single ip', async () => {
await find('192.168.0.242')
expect(cp.exec).toHaveBeenCalledWith('arp -n 192.168.0.242', { 'maxBuffer': TEN_MEGA_BYTE })
expect(cp.exec).toHaveBeenCalledWith('arp -n 192.168.0.242', { 'maxBuffer': TEN_MEGA_BYTE, 'timeout': ONE_MINUTE })
})
})
})
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ var servers = getServers()
var lock = {}

const TEN_MEGA_BYTE = 1024 * 1024 * 10
const ONE_MINUTE = 60 * 1000
const options = {
maxBuffer: TEN_MEGA_BYTE
maxBuffer: TEN_MEGA_BYTE,
timeout: ONE_MINUTE
}

/**
Expand Down

0 comments on commit 4403a8c

Please sign in to comment.