"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/rb/spec/unit/selenium/webdriver/socket_poller_spec.rb" (17 Feb 2023, 2537 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "socket_poller_spec.rb":
4.6.0_vs_4.7.0.
1 # frozen_string_literal: true
2
3 # Licensed to the Software Freedom Conservancy (SFC) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The SFC licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19
20 require_relative 'spec_helper'
21
22 module Selenium
23 module WebDriver
24 describe SocketPoller do
25 before(:context) do
26 @server_thread = Thread.new do
27 server = TCPServer.open(Platform.localhost, 9250)
28 Thread.current.thread_variable_set(:server, server)
29 loop { server.accept.close }
30 end
31 @server_thread.report_on_exception = false
32 end
33
34 after(:context) do
35 @server_thread.thread_variable_get(:server).close
36 end
37
38 def poller(port)
39 SocketPoller.new('localhost', port, 5, 0.05)
40 end
41
42 describe '#connected?' do
43 it 'returns true when the socket is listening' do
44 expect(poller(9250)).to be_connected
45 end
46
47 it 'returns false if the socket is not listening after the given timeout' do
48 start = Time.parse('2010-01-01 00:00:00')
49 wait = Time.parse('2010-01-01 00:00:04')
50 stop = Time.parse('2010-01-01 00:00:06')
51
52 allow(Process).to receive(:clock_gettime).and_return(start, wait, stop)
53 expect(poller(9251)).not_to be_connected
54 end
55 end
56
57 describe '#closed?' do
58 it 'returns true when the socket is closed' do
59 expect(poller(9251)).to be_closed
60 end
61
62 it 'returns false if the socket is still listening after the given timeout' do
63 start = Time.parse('2010-01-01 00:00:00').to_f
64 wait = Time.parse('2010-01-01 00:00:04').to_f
65 stop = Time.parse('2010-01-01 00:00:06').to_f
66
67 allow(Process).to receive(:clock_gettime).and_return(start, wait, stop)
68 expect(poller(9250)).not_to be_closed
69 end
70 end
71 end
72 end # WebDriver
73 end # Selenium