~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to test/simple/test-fs-read-stream.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
var fn = path.join(common.fixturesDir, 'elipses.txt');
35
35
var rangeFile = path.join(common.fixturesDir, 'x.txt');
36
36
 
37
 
var callbacks = { open: 0, end: 0, close: 0, destroy: 0 };
 
37
var callbacks = { open: 0, end: 0, close: 0 };
38
38
 
39
39
var paused = false;
40
40
 
60
60
 
61
61
  paused = true;
62
62
  file.pause();
63
 
  assert.ok(file.paused);
64
63
 
65
64
  setTimeout(function() {
66
65
    paused = false;
67
66
    file.resume();
68
 
    assert.ok(!file.paused);
69
67
  }, 10);
70
68
});
71
69
 
77
75
 
78
76
file.on('close', function() {
79
77
  callbacks.close++;
80
 
  assert.ok(!file.readable);
81
78
 
82
79
  //assert.equal(fs.readFileSync(fn), fileContent);
83
80
});
84
81
 
85
 
var file2 = fs.createReadStream(fn);
86
 
file2.destroy(function(err) {
87
 
  assert.ok(!err);
88
 
  callbacks.destroy++;
89
 
});
90
 
 
91
82
var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
92
83
file3.length = 0;
93
84
file3.on('data', function(data) {
107
98
process.on('exit', function() {
108
99
  assert.equal(1, callbacks.open);
109
100
  assert.equal(1, callbacks.end);
110
 
  assert.equal(1, callbacks.destroy);
111
 
 
112
101
  assert.equal(2, callbacks.close);
113
 
 
114
102
  assert.equal(30000, file.length);
115
103
  assert.equal(10000, file3.length);
 
104
  console.error('ok');
116
105
});
117
106
 
118
107
var file4 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1, end: 2});
162
151
var pauseRes = fs.createReadStream(rangeFile);
163
152
pauseRes.pause();
164
153
pauseRes.resume();
 
154
 
 
155
var file7 = fs.createReadStream(rangeFile, {autoClose: false });
 
156
file7.on('data', function() {});
 
157
file7.on('end', function() {
 
158
  process.nextTick(function() {
 
159
    assert(!file7.closed);
 
160
    assert(!file7.destroyed);
 
161
    file7Next();
 
162
  });
 
163
});
 
164
 
 
165
function file7Next(){
 
166
  // This will tell us if the fd is usable again or not.
 
167
  file7 = fs.createReadStream(null, {fd: file7.fd, start: 0 });
 
168
  file7.data = '';
 
169
  file7.on('data', function(data) {
 
170
    file7.data += data;
 
171
  });
 
172
  file7.on('end', function(err) {
 
173
    assert.equal(file7.data, 'xyz\n');
 
174
    process.nextTick(function() {
 
175
      assert(file7.closed);
 
176
      assert(file7.destroyed);
 
177
    });
 
178
  });
 
179
}
 
180
 
 
181
// Just to make sure autoClose won't close the stream because of error.
 
182
var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
 
183
file8.on('data', function() {});
 
184
file8.on('error', common.mustCall(function() {}));
 
185
file8.on('end', function() {
 
186
  process.nextTick(function() {
 
187
    assert(!file8.closed);
 
188
    assert(!file8.destroyed);
 
189
    assert(file8.fd);
 
190
  });
 
191
});