Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit d7f6bcca
authored
Feb 21, 2014
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complex test that fails on pg
1 parent
b1f666e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
1 deletions
package.json
test/sequelize.transaction.test.js
package.json
View file @
d7f6bcc
...
...
@@ -69,7 +69,8 @@
"istanbul"
:
"~0.1.45"
,
"coveralls"
:
"~2.7.1"
,
"async"
:
"~0.2.10"
,
"coffee-script"
:
"~1.7.1"
"coffee-script"
:
"~1.7.1"
,
"q"
:
"~1.0.0"
},
"keywords"
:
[
"mysql"
,
...
...
test/sequelize.transaction.test.js
View file @
d7f6bcc
...
...
@@ -116,4 +116,130 @@ describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () {
}).
done
(
done
)
})
})
describe
(
'complex long running example'
,
function
()
{
it
(
"works"
,
function
(
done
)
{
var
Q
=
require
(
'q'
),
http
=
require
(
'http'
),
sequelize
=
this
.
sequelize
,
properties
=
{
id
:
{
type
:
Support
.
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
name
:
{
type
:
Support
.
Sequelize
.
STRING
}
},
Test
=
sequelize
.
define
(
'Test'
,
properties
);
function
createTable
()
{
var
deferred
=
Q
.
defer
();
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
console
.
info
(
'Database: created table'
);
deferred
.
resolve
();
}).
error
(
function
(
error
)
{
console
.
error
(
error
);
deferred
.
reject
();
});
return
deferred
.
promise
;
}
function
createUser
(
transaction
)
{
var
deferred
=
Q
.
defer
();
Test
.
create
({
name
:
'Peter'
},
{
transaction
:
transaction
})
.
success
(
function
(
createdUser
)
{
console
.
info
(
'Database: created new user'
);
deferred
.
resolve
(
createdUser
);
}).
error
(
function
(
error
)
{
console
.
error
(
error
);
deferred
.
reject
();
});
return
deferred
.
promise
;
}
function
foobarbaz
(
u
)
{
var
deferred
=
Q
.
defer
();
setTimeout
(
function
()
{
deferred
.
resolve
()
},
1000
)
// http.get("http://mandrillapp.com/api/1.0/messages/send-template.json", function (response) {
// console.log("Got response: " + response.statusCode);
// deferred.resolve(u);
// }).on('error', function (e) {
// console.log("Got error: " + e.message);
// deferred.reject();
// });
return
deferred
.
promise
;
}
function
doStuff
(
transaction
)
{
return
createUser
(
transaction
)
.
then
(
function
()
{
return
readTests
(
'Before http call without transaction'
)
})
.
then
(
function
()
{
return
readTests
(
'Before http call with transaction'
,
transaction
)
})
.
then
(
function
(){
return
foobarbaz
()
})
.
then
(
function
()
{
return
readTests
(
'Directly after http call without transaction'
)
})
.
then
(
function
()
{
return
readTests
(
'Directly after http call with transaction'
,
transaction
)
})
}
function
readTests
(
msg
,
transaction
)
{
var
deferred
=
Q
.
defer
()
console
.
log
(
"-"
,
msg
)
Test
.
count
({
transaction
:
transaction
}).
done
(
function
(
err
,
count
)
{
console
.
log
(
err
,
count
)
!!
err
?
deferred
.
reject
()
:
deferred
.
resolve
()
})
return
deferred
.
promise
}
function
run
()
{
var
deferred
=
Q
.
defer
();
sequelize
.
transaction
(
function
(
transaction
)
{
transaction
.
done
(
function
()
{
console
.
log
()
console
.
log
(
'xxxxxxxxx transaction has been executed'
)
console
.
log
()
})
doStuff
(
transaction
)
.
then
(
function
()
{
return
readTests
(
'After the http call without transaction'
)
})
.
then
(
function
()
{
return
readTests
(
'After the http call with transaction'
,
transaction
)
})
.
then
(
function
(
result
)
{
transaction
.
commit
().
success
(
function
()
{
console
.
log
(
'Commit!'
);
deferred
.
resolve
();
});
})
.
fail
(
function
(
error
)
{
transaction
.
rollback
().
success
(
function
()
{
console
.
log
(
'Rollback!'
);
deferred
.
reject
();
});
});
});
return
deferred
.
promise
;
}
createTable
()
.
then
(
function
()
{
return
readTests
(
'After table creation without transaction'
)
})
.
then
(
run
)
.
then
(
function
()
{
return
readTests
(
'After committing the transaction'
)
})
.
done
(
function
()
{
Test
.
all
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
to
.
equal
(
1
)
console
.
log
(
'Done!'
);
done
()
})
});
})
})
})
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment