Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic integration tests #67

Merged
merged 48 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e0d47fc
Add automatic integration tests
jaakkos Nov 28, 2022
cd4d6a3
dont ignore folder
jaakkos Nov 28, 2022
e6a3782
add target winston version for easier debug
jaakkos Nov 28, 2022
91106ae
Fix base package.json
jaakkos Nov 28, 2022
ebbc2f6
Wait for logstahs
jaakkos Nov 28, 2022
e0d8175
wait
jaakkos Nov 28, 2022
b72ed57
Next try
jaakkos Nov 28, 2022
b718a37
Next try
jaakkos Nov 28, 2022
fe8bf65
Next try
jaakkos Nov 28, 2022
b5be4b4
Next try
jaakkos Nov 28, 2022
d5b81fe
Next try
jaakkos Nov 28, 2022
857ec73
Next try
jaakkos Nov 30, 2022
3470260
Next try
jaakkos Nov 30, 2022
242aee7
Next try
jaakkos Nov 30, 2022
72c54fe
Next try
jaakkos Nov 30, 2022
d37895f
Next try
jaakkos Nov 30, 2022
ade179c
Next try
jaakkos Nov 30, 2022
ddd506e
Next try
jaakkos Nov 30, 2022
bac04fe
Next try
jaakkos Nov 30, 2022
e89831c
Next try
jaakkos Nov 30, 2022
563085b
Next try
jaakkos Nov 30, 2022
41bb15c
Next try
jaakkos Nov 30, 2022
65be9da
Next try
jaakkos Nov 30, 2022
dedd054
Next try
jaakkos Nov 30, 2022
7eb3bc4
Next try
jaakkos Nov 30, 2022
534c8fe
Next try
jaakkos Nov 30, 2022
096312a
Next try
jaakkos Nov 30, 2022
5791b0e
Fix issues with retry logic
jaakkos Dec 2, 2022
65713cd
Change path
jaakkos Dec 2, 2022
05df23d
Change path
jaakkos Dec 2, 2022
304dd1b
Change path
jaakkos Dec 2, 2022
262cd90
Change path
jaakkos Dec 2, 2022
57c42b7
Writable folder
jaakkos Dec 2, 2022
a128a8e
Writable folder
jaakkos Dec 2, 2022
837de9f
Writable folder
jaakkos Dec 2, 2022
3e1510a
Writable folder
jaakkos Dec 2, 2022
e713c88
Writable folder
jaakkos Dec 2, 2022
8d61e94
Writable folder
jaakkos Dec 2, 2022
6173ff9
Writable folder
jaakkos Dec 2, 2022
99654ba
Writable folder
jaakkos Dec 2, 2022
8abe3a2
Writable folder
jaakkos Dec 2, 2022
db88b38
Writable folder
jaakkos Dec 2, 2022
6130e19
Writable folder
jaakkos Dec 2, 2022
c19ce6c
Writable folder
jaakkos Dec 2, 2022
5ac04ff
Writable folder
jaakkos Dec 2, 2022
65b24db
Writable folder
jaakkos Dec 2, 2022
8d57de3
Writable folder
jaakkos Dec 2, 2022
ba1fdc2
Writable folder
jaakkos Dec 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Integration tests with Logstash instanse

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
timeout-minutes: 2
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 19.x]
winston-version: [2x, 3x]

steps:
- uses: actions/checkout@v3
- name: Start containers for Winston ${{ matrix.winston-version }}
working-directory: ./test-bench/logstash/
run: docker-compose -f "docker-compose.yml" up -d
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install base project deps
run: npm install
- name: Build base project
run: npm run build
- name: Install dependencies for test case
working-directory: ./test-bench/winston-${{ matrix.winston-version }}
run: npm install
- name: Wait for Logstash
working-directory: ./test-bench/logstash/
run: |
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9777 &&
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9888 &&
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9999 &&
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9777 &&
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9888 &&
npx --yes wait-on --timeout 3000 --verbose tcp:localhost:9999 &&
docker-compose logs --no-color logstash
- run: npm test
working-directory: ./test-bench/winston-${{ matrix.winston-version }}
- name: Stop containers
working-directory: ./test-bench/logstash/
if: always()
run: |
docker-compose logs --no-color logstash &&
docker-compose -f "docker-compose.yml" down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ test/runner.js

test/support/logstash/*

test-bench/logstash/logstash/output/*
!test-bench/logstash/logstash/output/.gitkeep
test-bench/logstash/logstash/output/sample.log
23 changes: 14 additions & 9 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ class Manager extends _events.EventEmitter {
_defineProperty(this, "retries", -1);
_defineProperty(this, "max_connect_retries", void 0);
_defineProperty(this, "timeout_connect_retries", void 0);
_defineProperty(this, "retry_timeout", undefined);
this.options = options;
this.ssl_enable = (options === null || options === void 0 ? void 0 : options.ssl_enable) === true;
this.logQueue = new Array();

// Connection retry attributes
this.retries = -1;
this.retries = 0;
this.max_connect_retries = (_options$max_connect_ = options === null || options === void 0 ? void 0 : options.max_connect_retries) !== null && _options$max_connect_ !== void 0 ? _options$max_connect_ : 4;
this.timeout_connect_retries = (_options$timeout_conn = options === null || options === void 0 ? void 0 : options.timeout_connect_retries) !== null && _options$timeout_conn !== void 0 ? _options$timeout_conn : 100;
}
addEventListeners() {
this.on('connection:connected', this.onConnected.bind(this));
this.on('connection:closed', this.onConnectionClosed.bind(this));
this.on('connection:error', this.onConnectionError.bind(this));
this.on('connection:timeout', this.onConnectionError.bind(this));
this.once('connection:connected', this.onConnected.bind(this));
this.once('connection:closed', this.onConnectionClosed.bind(this));
this.once('connection:error', this.onConnectionError.bind(this));
this.once('connection:timeout', this.onConnectionError.bind(this));
}
removeEventListeners() {
this.off('connection:connected', this.onConnected.bind(this));
Expand All @@ -59,7 +60,7 @@ class Manager extends _events.EventEmitter {
isRetryableError(error) {
// TODO: Due bug in the orginal implementation
// all the errors will get retried
return true; // !ECONNREFUSED_REGEXP.test(error.code);
return true; // !ECONNREFUSED_REGEXP.test(error.message);
}

shouldTryToReconnect(error) {
Expand All @@ -75,22 +76,26 @@ class Manager extends _events.EventEmitter {
}
onConnectionError(error) {
if (this.shouldTryToReconnect(error)) {
this.retry();
} else {
var _this$connection;
this.removeEventListeners();
(_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.close();
this.emit('error', new Error('Max retries reached, transport in silent mode, OFFLINE'));
} else {
this.retry();
}
}
retry() {
var _this$connection2;
if (this.retry_timeout) {
clearTimeout(this.retry_timeout);
}
this.emit('retrying');
this.removeEventListeners();
const self = this;
this.once('connection:closed', () => {
self.removeEventListeners();
setInterval(() => {
self.retry_timeout = setTimeout(() => {
self.connection = undefined;
self.start();
}, self.timeout_connect_retries);
});
Expand Down
Loading