A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
972 B

12 years ago
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'stream_test';
  6. connection.query([
  7. 'CREATE TEMPORARY TABLE `' + table + '` (',
  8. '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
  9. '`title` varchar(255),',
  10. 'PRIMARY KEY (`id`)',
  11. ') ENGINE=InnoDB DEFAULT CHARSET=utf8'
  12. ].join('\n'));
  13. var rowCount = 10;
  14. for (var i = 1; i <= rowCount; i++) {
  15. var row = {
  16. id: i,
  17. title: 'Row #' + i,
  18. };
  19. connection.query('INSERT INTO ' + table + ' SET ?', row);
  20. }
  21. var query = connection.query('SELECT * FROM ' + table);
  22. var hadEnd = false;
  23. var rows = [];
  24. var fields = undefined;
  25. query.on('result', function(row) {
  26. connection.pause();
  27. connection.resume();
  28. rows.push(row);
  29. })
  30. .on('end', function() {
  31. hadEnd = true;
  32. });
  33. connection.end();
  34. process.on('exit', function() {
  35. assert.equal(rows.length, rowCount);
  36. assert.equal(hadEnd, true);
  37. });