Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implemented HTTP CLIENT

  • Loading branch information...
commit 9faeda4f1b9c9e5efbdb2cacdb2cf35595b9fb13 1 parent 8a7910b
@rvagg rvagg authored
View
56 exercises/http_client/exercise.js
@@ -1 +1,55 @@
-// code stuff here
+var http = require('http')
+ , exercise = require('workshopper-exercise')()
+ , filecheck = require('workshopper-exercise/filecheck')
+ , execute = require('workshopper-exercise/execute')
+ , comparestdout = require('workshopper-exercise/comparestdout')
+
+ , words = require('boganipsum/clean_words')
+ .sort(function () { return 0.5 - Math.random() })
+ .slice(0, 10)
+
+
+// checks that the submission file actually exists
+exercise = filecheck(exercise)
+
+// execute the solution and submission in parallel with spawn()
+exercise = execute(exercise)
+
+// compare stdout of solution and submission
+exercise = comparestdout(exercise)
+
+
+// set up the data file to be passed to the submission
+exercise.addSetup(function (mode, callback) {
+ // mode == 'run' || 'verify'
+
+ this.server = http.createServer(function (req, res) {
+ // use setTimeout to slow down the output to test timing
+ ;(function next (i) {
+ if (i == words.length)
+ return res.end()
+ res.write(words[i].trim())
+ setTimeout(next.bind(null, i + 1), 10)
+ }(0))
+ })
+
+ this.server.listen(0, function () {
+ var url = 'http://localhost:' + String(this.server.address().port)
+
+ this.submissionArgs.unshift(url)
+ this.solutionArgs.unshift(url)
+
+ callback()
+ }.bind(this))
+})
+
+
+// cleanup for both run and verify
+exercise.addCleanup(function (mode, passed, callback) {
+ // mode == 'run' || 'verify'
+
+ this.server.close(callback)
+})
+
+
+module.exports = exercise
View
7 exercises/http_client/solution.js
@@ -1,7 +0,0 @@
-var http = require('http')
-
-http.get(process.argv[2], function (response) {
- response.setEncoding('utf8')
- response.on('data', console.log)
- response.on('error', console.error)
-})
View
8 exercises/http_client/solution/solution.js
@@ -1 +1,7 @@
-// code stuff here
+var http = require('http')
+
+http.get(process.argv[2], function (response) {
+ response.setEncoding('utf8')
+ response.on('data', console.log)
+ response.on('error', console.error)
+})
View
0  lib/rndport.js
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.