~ubuntu-branches/ubuntu/vivid/nodejs/vivid

« back to all changes in this revision

Viewing changes to .pc/2007_remove_internet_test.patch/test/simple/test-net-connect-timeout.js

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2011-06-30 19:48:43 UTC
  • Revision ID: james.westby@ubuntu.com-20110630194843-l2obxusuyxw72hu7
Tags: 0.4.9-1ubuntu3
2007_remove_internet_test.patch: updated to remove more one test that needs
internet connections (test-net-connect-timeout)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright Joyent, Inc. and other Node contributors.
 
2
//
 
3
// Permission is hereby granted, free of charge, to any person obtaining a
 
4
// copy of this software and associated documentation files (the
 
5
// "Software"), to deal in the Software without restriction, including
 
6
// without limitation the rights to use, copy, modify, merge, publish,
 
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
 
8
// persons to whom the Software is furnished to do so, subject to the
 
9
// following conditions:
 
10
//
 
11
// The above copyright notice and this permission notice shall be included
 
12
// in all copies or substantial portions of the Software.
 
13
//
 
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
// This example attempts to time out before the connection is established
 
23
// https://groups.google.com/forum/#!topic/nodejs/UE0ZbfLt6t8
 
24
// https://groups.google.com/forum/#!topic/nodejs-dev/jR7-5UDqXkw
 
25
//
 
26
// TODO: how to do this without relying on the responses of specific sites?
 
27
 
 
28
var common = require('../common');
 
29
var net = require('net');
 
30
var assert = require('assert');
 
31
 
 
32
var start = new Date();
 
33
 
 
34
var gotTimeout0 = false;
 
35
var gotTimeout1 = false;
 
36
 
 
37
var gotConnect0 = false;
 
38
var gotConnect1 = false;
 
39
 
 
40
var T = 100;
 
41
 
 
42
 
 
43
// With DNS
 
44
 
 
45
var socket0 = net.createConnection(9999, 'google.com');
 
46
 
 
47
socket0.setTimeout(T);
 
48
 
 
49
socket0.on('timeout', function() {
 
50
  console.error("timeout");
 
51
  gotTimeout0 = true;
 
52
  var now = new Date();
 
53
  assert.ok(now - start < T + 500);
 
54
  socket0.destroy();
 
55
});
 
56
 
 
57
socket0.on('connect', function() {
 
58
  console.error("connect");
 
59
  gotConnect0 = true;
 
60
  socket0.destroy();
 
61
});
 
62
 
 
63
 
 
64
// Without DNS
 
65
 
 
66
var socket1 = net.createConnection(9999, '24.24.24.24');
 
67
 
 
68
socket1.setTimeout(T);
 
69
 
 
70
socket1.on('timeout', function() {
 
71
  console.error("timeout");
 
72
  gotTimeout1 = true;
 
73
  var now = new Date();
 
74
  assert.ok(now - start < T + 500);
 
75
  socket1.destroy();
 
76
});
 
77
 
 
78
socket1.on('connect', function() {
 
79
  console.error("connect");
 
80
  gotConnect1 = true;
 
81
  socket1.destroy();
 
82
});
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
process.on('exit', function() {
 
89
  assert.ok(gotTimeout0);
 
90
  assert.ok(!gotConnect0);
 
91
 
 
92
  assert.ok(gotTimeout1);
 
93
  assert.ok(!gotConnect1);
 
94
});