不要怂,就是干,撸起袖子干!

Commit 4ab48f75 by Sascha Depold

Another test for transactions with concurrency

1 parent 93b0daa1
Showing with 47 additions and 1 deletions
......@@ -4,7 +4,8 @@ var chai = require('chai')
, Transaction = require(__dirname + '/../lib/transaction')
describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () {
this.timeout(4000);
this.timeout(4000)
describe('success', function() {
it("gets triggered once a transaction has been successfully committed", function(done) {
this
......@@ -147,4 +148,49 @@ describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () {
})
})
})
describe('concurrency', function() {
describe('having tables with uniqueness constraints', function() {
beforeEach(function(done) {
var self = this
Support.prepareTransactionTest(this.sequelize, function(sequelize) {
self.sequelize = sequelize
self.Model = sequelize.define('Model', {
name: { type: Support.Sequelize.STRING, unique: true }
}, {
timestamps: false
})
self.Model
.sync({ force: true })
.success(function() { done() })
})
})
it("triggers the error event for the second transactions", function(done) {
var self = this
this.sequelize.transaction(function(t1) {
self.sequelize.transaction(function(t2) {
self
.Model
.create({ name: 'omnom' }, { transaction: t1 })
.success(function(m1) {
self
.Model
.create({ name: 'omnom' }, { transaction: t2 })
.error(function(err) {
expect(err).to.be.defined
done()
})
setTimeout(function() { t1.commit() }, 100)
})
})
})
})
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!