-
Notifications
You must be signed in to change notification settings - Fork 98
fix: servient.shutdown does not close open http connections #1548
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
Open
DhairyaMajmudar
wants to merge
1
commit into
eclipse-thingweb:master
Choose a base branch
from
DhairyaMajmudar:1506-servient_shutdown
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and | ||
| * Document License (2015-05-13) which is available at | ||
| * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 | ||
| ********************************************************************************/ | ||
|
|
||
| import { suite, test } from "@testdeck/mocha"; | ||
| import chai, { expect, should } from "chai"; | ||
| import spies from "chai-spies"; | ||
|
|
||
| import HttpClientFactory from "../src/http-client-factory"; | ||
| import HttpsClientFactory from "../src/https-client-factory"; | ||
| import HttpClient from "../src/http-client"; | ||
|
|
||
| should(); | ||
| chai.use(spies); | ||
|
|
||
| @suite("HTTP client lifecycle") | ||
| class HttpClientLifecycleTest { | ||
| @test "HTTP factory destruction stops every created client"() { | ||
| const factory = new HttpClientFactory(); | ||
| const firstClient = factory.getClient(); | ||
| const secondClient = factory.getClient(); | ||
| const firstStop = chai.spy.on(firstClient, "stop"); | ||
| const secondStop = chai.spy.on(secondClient, "stop"); | ||
|
|
||
| expect(factory.destroy()).to.equal(true); | ||
|
|
||
| firstStop.should.have.been.called.once; | ||
| secondStop.should.have.been.called.once; | ||
| } | ||
|
|
||
| @test "HTTPS factory destruction stops every created client"() { | ||
| const factory = new HttpsClientFactory(); | ||
| const firstClient = factory.getClient(); | ||
| const secondClient = factory.getClient(); | ||
| const firstStop = chai.spy.on(firstClient, "stop"); | ||
| const secondStop = chai.spy.on(secondClient, "stop"); | ||
|
|
||
| expect(factory.destroy()).to.equal(true); | ||
|
|
||
| firstStop.should.have.been.called.once; | ||
| secondStop.should.have.been.called.once; | ||
| } | ||
|
|
||
| @test async "client stop closes and clears active subscriptions"() { | ||
| const client = new HttpClient(); | ||
| const close = chai.spy(); | ||
| client["activeSubscriptions"].set("http://example.test/observation", { | ||
| open: async () => undefined, | ||
| close, | ||
| }); | ||
|
|
||
| await client.stop(); | ||
|
|
||
| close.should.have.been.called.once; | ||
| expect(client["activeSubscriptions"].size).to.equal(0); | ||
| } | ||
|
|
||
| @test async "unlink closes and forgets the active subscription"() { | ||
| const client = new HttpClient(); | ||
| const close = chai.spy(); | ||
| const href = "http://example.test/observation"; | ||
| client["activeSubscriptions"].set(href, { | ||
| open: async () => undefined, | ||
| close, | ||
| }); | ||
|
|
||
| await client.unlinkResource({ href }); | ||
|
|
||
| close.should.have.been.called.once; | ||
| expect(client["activeSubscriptions"].has(href)).to.equal(false); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question about why using Set instead of an array. I wonder whether it can happen that a HttpClient may be treated as duplicate... hence creating for example 2 HttpClient instances but having just one entry in the set...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielpeintner , I used a Set to avoid accidentally tracking the same instance more than once, but I’m happy to use an array for consistency with MqttClientFactory if you prefer.