-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: avoid early release of PostgresQueryRunner (#7109) If the QueryRunner is not connected yet, release is a no-op * fix: avoid early release of PostgresQueryRunner (#7109) Revert no-op driver-wide early release, fix only for stream case. * fix: avoid early release of PostgresQueryRunner (#7109) Restrict stream unit test to drivers who implement the stream interface * fix: avoid early release of PostgresQueryRunner (#7109) Restrict unit test to drivers whose stream implementation works in master
- Loading branch information
1 parent
66df9f1
commit 9abe007
Showing
5 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,13 @@ | ||
import {Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
||
@Entity() | ||
export class Dummy { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
field: string; | ||
|
||
} |
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,46 @@ | ||
import "reflect-metadata"; | ||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {Dummy} from './entity/Dummy'; | ||
import {ReadStream} from 'fs'; | ||
import {expect} from "chai"; | ||
|
||
function ingestStream (stream: ReadStream): Promise<any[]> { | ||
let chunks: any[] = []; | ||
return new Promise((resolve, reject) => { | ||
stream.on('data', chunk => chunks.push(chunk)) | ||
stream.on('error', reject) | ||
stream.on('end', () => resolve(chunks)) | ||
}) | ||
} | ||
|
||
describe("github issues > #7109 stream() bug from 0.2.25 to 0.2.26 with postgresql", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
enabledDrivers: ["postgres", "mysql", "mariadb", "cockroachdb"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should release the QueryRunner created by a SelectQueryBuilder", () => Promise.all(connections.map(async connection => { | ||
const values = [{field: "abc"}, {field: "def"}, {field: "ghi"}]; | ||
// First create some test data | ||
await connection.createQueryBuilder() | ||
.insert() | ||
.into(Dummy) | ||
.values(values) | ||
.execute(); | ||
|
||
// Stream data: | ||
const stream = await connection.createQueryBuilder().from(Dummy, 'dummy').select('field').stream(); | ||
const streamedEntities = await ingestStream(stream); | ||
|
||
// If the runner is properly released, the test is already successful; this assert is just a sanity check. | ||
const extractFields = (val: {field: string}) => val.field; | ||
expect(streamedEntities.map(extractFields)).to.have.members(values.map(extractFields)); | ||
|
||
}))); | ||
}); |