This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from applandinc/fix/sql-transaction-scope
Correctly enumerate transaction events
- Loading branch information
Showing
9 changed files
with
87 additions
and
54 deletions.
There are no files selected for viewing
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
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
Git LFS file not shown
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import CommandScope from '../../src/scope/commandScope'; | ||
import { fixtureAppMap } from '../util'; | ||
|
||
describe('command scope', () => { | ||
it('emits http_server_request command with child events', async () => { | ||
const appmap = await fixtureAppMap( | ||
'org_springframework_samples_petclinic_owner_OwnerControllerTests_testInitCreationForm.appmap.json' | ||
); | ||
const scopes = [...new CommandScope().scopes(appmap.events[Symbol.iterator]())]; | ||
expect(scopes.map((scope) => scope.scope.id)).toEqual([1]); | ||
expect(scopes.map((scope) => scope.scope.toString())).toEqual(['GET /owners/new']); | ||
|
||
const requestEvents = Array.from(scopes[0].events()); | ||
expect(requestEvents.length).toEqual(4); | ||
}); | ||
}); |
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,22 @@ | ||
import RootScope from '../../src/scope/rootScope'; | ||
import { fixtureAppMap } from '../util'; | ||
|
||
describe('root scope', () => { | ||
it('emits a scope for each root event', async () => { | ||
const appmap = await fixtureAppMap( | ||
'org_springframework_samples_petclinic_owner_OwnerControllerTests_testInitCreationForm.appmap.json' | ||
); | ||
const scopes = [...new RootScope().scopes(appmap.events[Symbol.iterator]())]; | ||
expect(scopes.map((scope) => scope.scope.id)).toEqual([1, 9]); | ||
expect(scopes.map((scope) => scope.scope.toString())).toEqual([ | ||
'GET /owners/new', | ||
'org/springframework/samples/petclinic/model/BaseEntity#isNew', | ||
]); | ||
|
||
const requestEvents = Array.from(scopes[0].events()); | ||
expect(requestEvents.length).toEqual(4); | ||
|
||
const fnEvents = Array.from(scopes[1].events()); | ||
expect(fnEvents.length).toEqual(1); | ||
}); | ||
}); |
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,40 @@ | ||
import assert from 'node:assert'; | ||
import SQLTransactionScope, { hasTransactionDetails } from '../../src/scope/sqlTransactionScope'; | ||
import { Scope } from '../../src/types'; | ||
import { fixtureAppMap } from '../util'; | ||
|
||
function next<T>(iter: Iterator<T>): T { | ||
const result = iter.next(); | ||
assert(!result.done); | ||
return result.value; | ||
} | ||
|
||
describe('SQL transaction scope', () => { | ||
it('emits a scope for each SQL transaction', async () => { | ||
const appMap = await fixtureAppMap('sqlTransactionScopeTest.appmap.json'); | ||
|
||
const scopes = new SQLTransactionScope().scopes(appMap.events[Symbol.iterator]()); | ||
|
||
const committed: Scope = next(scopes); | ||
assert(hasTransactionDetails(committed.scope)); | ||
expect(committed.scope.transaction.status).toBe('commit'); | ||
expect([...committed.events()].length).toBe(3); | ||
|
||
const rolledBack: Scope = next(scopes); | ||
assert(hasTransactionDetails(rolledBack.scope)); | ||
expect(rolledBack.scope.transaction.status).toBe('rollback'); | ||
expect([...rolledBack.events()].length).toBe(3); | ||
|
||
const mockWarn = jest.spyOn(console, 'warn').mockImplementation(); | ||
const rest: Scope = next(scopes); | ||
assert(hasTransactionDetails(rest.scope)); | ||
expect(rest.scope.transaction.status).toBe('rollback'); | ||
expect([...rest.events()].length).toBe(2); | ||
expect(mockWarn).toHaveBeenCalledWith( | ||
expect.stringContaining('transaction started within a transaction') | ||
); | ||
mockWarn.mockRestore(); | ||
|
||
expect(scopes.next().done).toBeTruthy(); | ||
}); | ||
}); |