Skip to content

Instantly share code, notes, and snippets.

@zapu
Last active December 27, 2019 13:42
Show Gist options
  • Save zapu/173bd8dc07ce8c2210fefcaef5f2d4a4 to your computer and use it in GitHub Desktop.
Save zapu/173bd8dc07ce8c2210fefcaef5f2d4a4 to your computer and use it in GitHub Desktop.
Stress test for toffee
toffee = require './index'
fs = require 'fs'
path = require 'path'
os = require 'os'
# Create pressure on the node runtime to force infavorable preemption ordering in toffee.
pressure = () ->
loop
Buffer.alloc(1024).fill('A')
await setTimeout defer(), 10 * Math.random()
pressure() for _ in [0...100]
# Create temp dir and temp file
tmpDir = fs.mkdtempSync path.join os.tmpdir(), 'toffee-'
tmpFilename = path.join(tmpDir, 'x.toffee')
bufx = "hello world" + Buffer.alloc(4096).fill(' ').toString('utf8')
fs.writeFileSync(tmpFilename, bufx)
engine = new toffee.engine { verbose: true }
await engine.run tmpFilename, {}, defer err, res
console.log res.substring(0,11)
await setTimeout defer(), 1000
failure = false
for i in [0...1000]
text = bufx
await fs.writeFile tmpFilename, text, defer()
await fs.writeFile tmpFilename, text, defer()
# 0.5 seconds should be plenty - the background toffee reload should not take
# more than 100 ms to read the file and recompile template.
await setTimeout defer(), 500
console.log 'Calling engine.run now'
await engine.run tmpFilename, {}, defer err, res
if err
console.error 'Got error',err
failure = true
break
console.log 'Result is:', res.trim()
if res.trim().length is 0
console.error "ERROR"
content = fs.readFileSync tmpFilename
console.log 'read file:', content.toString().trim()
failure = true
break
# Remove temp dir
fs.unlinkSync(tmpFilename)
fs.rmdirSync(tmpDir)
process.exit if failure then 1 else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment