File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,13 @@ export default class Repository {
26
26
if ( this . rawRepository ) throw new Error ( 'A transaction is already started. Nested transactions are not supported.' )
27
27
28
28
return this . rawRepositoryPool . enqueue ( async ( rawRepositoryPromise ) => {
29
- this . rawRepository = await rawRepositoryPromise
30
- let result = await fn ( )
31
- this . rawRepository = null
32
- return result
29
+ try {
30
+ this . rawRepository = await rawRepositoryPromise
31
+ let result = await fn ( )
32
+ return result
33
+ } finally {
34
+ this . rawRepository = null
35
+ }
33
36
} )
34
37
}
35
38
Original file line number Diff line number Diff line change @@ -38,13 +38,24 @@ describe('Repository', () => {
38
38
assert . deepEqual ( actualEvents , expectedEvents )
39
39
} )
40
40
41
- it ( 'does not allow transactions to nest' , async function ( ) {
41
+ it ( 'does not allow transactions to nest' , async ( ) => {
42
42
const workingDirPath = copyRepositoryDir ( 1 )
43
43
const repo = await buildRepository ( workingDirPath )
44
44
await repo . transact ( function ( ) {
45
45
assert . throws ( ( ) => repo . transact ( ) , / N e s t e d t r a n s a c t i o n / )
46
46
} )
47
47
} )
48
+
49
+ it ( 'allows to create a new transaction if the previous one throws an error' , async ( ) => {
50
+ const workingDirPath = copyRepositoryDir ( 1 )
51
+ const repo = await buildRepository ( workingDirPath )
52
+ let executed = false
53
+ try {
54
+ await repo . transact ( async ( ) => { throw new Error ( 'An error!' ) } )
55
+ } catch ( e ) { }
56
+ await repo . transact ( async ( ) => { executed = true } )
57
+ assert ( executed )
58
+ } )
48
59
} )
49
60
50
61
describe ( 'refreshing' , ( ) => {
You can’t perform that action at this time.
0 commit comments