-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(instr-http): add two more small sanity tests: POST, SPAN_KIND_SE…
…RVER Closes: #31
- Loading branch information
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
packages/opentelemetry-node/test/fixtures/use-http-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Usage: node -r ../../start.js use-http-server.js | ||
// | ||
// This starts a simple echo server, makes two requests to it, then stops the | ||
// server. | ||
|
||
const http = require('http'); | ||
|
||
const server = http.createServer(function onRequest(req, res) { | ||
console.log('incoming request: %s %s %s', req.method, req.url, req.headers); | ||
if (req.url !== '/echo') { | ||
req.resume(); | ||
res.writeHead(404); | ||
res.end(); | ||
return; | ||
} | ||
if (req.method !== 'POST') { | ||
req.resume(); | ||
res.writeHead(405, { | ||
Allow: 'POST', | ||
}); | ||
res.end(); | ||
return; | ||
} | ||
|
||
const chunks = []; | ||
req.on('data', (chunk) => { | ||
chunks.push(chunk); | ||
}); | ||
req.on('end', function () { | ||
const body = Buffer.concat(chunks); | ||
res.writeHead(200, { | ||
'content-type': 'application/octet-stream', | ||
'content-length': Buffer.byteLength(body), | ||
}); | ||
res.end(body); | ||
}); | ||
}); | ||
|
||
server.listen(0, '127.0.0.1', async function () { | ||
const port = server.address().port; | ||
|
||
// First request to show a client error. | ||
await new Promise((resolve) => { | ||
const clientReq = http.request( | ||
`http://127.0.0.1:${port}/`, | ||
function (cres) { | ||
console.log( | ||
'client response: %s %s', | ||
cres.statusCode, | ||
cres.headers | ||
); | ||
const chunks = []; | ||
cres.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
cres.on('end', function () { | ||
const body = chunks.join(''); | ||
console.log('client response body: %j', body); | ||
resolve(); | ||
}); | ||
} | ||
); | ||
clientReq.end(); | ||
}); | ||
|
||
// First request to show a client error. | ||
await new Promise((resolve) => { | ||
const clientReq = http.request( | ||
`http://127.0.0.1:${port}/echo`, | ||
{ | ||
method: 'POST', | ||
}, | ||
function (cres) { | ||
console.log( | ||
'client response: %s %s', | ||
cres.statusCode, | ||
cres.headers | ||
); | ||
const chunks = []; | ||
cres.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
cres.on('end', function () { | ||
const body = chunks.join(''); | ||
console.log('client response body: %j', body); | ||
resolve(); | ||
}); | ||
} | ||
); | ||
clientReq.write('hi'); | ||
clientReq.end(); | ||
}); | ||
|
||
server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Usage: node -r ../../start.js use-https-get.js | ||
const https = require('https'); | ||
https.get('https://www.google.com/', (res) => { | ||
console.log('client response: %s %s', res.statusCode, res.headers); | ||
res.resume(); | ||
res.on('end', () => { | ||
console.log('client response: end'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters