Skip to content

Commit

Permalink
[#182] Support gRPC stream flowable
Browse files Browse the repository at this point in the history
*  _read method of readable steam learning test


[#177] Update minimum NodeJS version to Node@16
  • Loading branch information
feelform committed Mar 25, 2024
1 parent 719afa7 commit 7d8461b
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 57 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
strategy:
matrix:
node_version:
- 14
- 16
- 18

Expand Down
58 changes: 58 additions & 0 deletions lib/client/bounded-buffer-readable-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Pinpoint Node.js Agent
* Copyright 2021-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

const { Readable } = require('node:stream')

class BoundedBufferReadableStream {
constructor(constructorOptions) {
this.buffer = []

const options = constructorOptions || {}
this.steam = new Readable(Object.assign({
read: () => {
this.readStart()
}
}, options))
}

push(data) {
if (!data) {
return
}
this.buffer.push(data)

if (this.canStart()) {
this.readStart()
}
}

canStart() {
return this.readable
}

end() {
this.steam.end()
}

readStart() {
this.readable = true

const length = this.buffer.length
for (let index = 0; index < length; index++) {
if (!this.steam.push(this.buffer.shift())) {
return this.readStop()
}
}
}

readStop() {
this.readable = false
}
}

module.exports = BoundedBufferReadableStream
104 changes: 52 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinpoint-node-agent",
"version": "0.9.0-next.4",
"version": "1.0.0-next.1",
"main": "index.js",
"types": "index.d.ts",
"type": "commonjs",
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/pinpoint-apm/pinpoint-node-agent",
"engines": {
"node": ">=14.0"
"node": ">=16.0"
},
"keywords": [
"pinpoint",
Expand Down Expand Up @@ -64,7 +64,7 @@
"devDependencies": {
"@types/semver": "^7.3.13",
"@types/shimmer": "^1.0.2",
"axios": "^1.6.2",
"axios": "^1.6.8",
"eslint": "^8.43.0",
"eslint-config-prettier": "^3.6.0",
"eslint-plugin-import": "^2.25.2",
Expand Down
2 changes: 1 addition & 1 deletion test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ test('Should initialize agent', function (t) {

const agent = require('./support/agent-singleton-mock')
t.ok(agent)
t.equal(agent.pinpointClient.agentInfo.agentVersion, '0.9.0-next.4', 'agent version from package.json')
t.equal(agent.pinpointClient.agentInfo.agentVersion, '1.0.0-next.1', 'agent version from package.json')
})
21 changes: 21 additions & 0 deletions test/client/bounded-buffer-readable-stream.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Pinpoint Node.js Agent
* Copyright 2021-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

const test = require('tape')
const BoundedBufferReadableStream = require('../../lib/client/bounded-buffer-readable-stream')

test('no piped readable steam', (t) => {
const readable = new BoundedBufferReadableStream()
readable.push('test1')
readable.push('test2')
readable.push(null)

t.equal(readable.steam.readable, true, 'no writable stream piped readable steam not started')
t.equal(readable.buffer.length, 2, 'no writable stream piped readable steam buffer is not empty')
t.end()
})

0 comments on commit 7d8461b

Please sign in to comment.