Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
2b92ff4e
Commit
2b92ff4e
authored
6 years ago
by
Paul Kaplan
Browse files
Options
Downloads
Patches
Plain Diff
Be more careful about when connection attempt is incremented
parent
7eb203b8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lib/cloud-provider.js
+3
-7
3 additions, 7 deletions
src/lib/cloud-provider.js
src/playground/render-gui.jsx
+5
-0
5 additions, 0 deletions
src/playground/render-gui.jsx
test/unit/util/cloud-provider.test.js
+11
-16
11 additions, 16 deletions
test/unit/util/cloud-provider.test.js
with
19 additions
and
23 deletions
src/lib/cloud-provider.js
+
3
−
7
View file @
2b92ff4e
...
...
@@ -58,20 +58,16 @@ class CloudProvider {
}
onOpen
()
{
this
.
connectionAttempts
=
1
;
// Reset because we successfully connected
this
.
connectionAttempts
=
0
;
// Reset because we successfully connected
this
.
writeToServer
(
'
handshake
'
);
log
.
info
(
`Successfully connected to clouddata server.`
);
}
onClose
()
{
log
.
info
(
`Closed connection to websocket`
);
this
.
connectionAttempts
+=
1
;
const
randomizedTimeout
=
this
.
randomizeDuration
(
this
.
exponentialTimeout
());
this
.
setTimeout
(
this
.
reconnectNow
.
bind
(
this
),
randomizedTimeout
);
}
reconnectNow
()
{
this
.
connectionAttempts
=
this
.
connectionAttempts
+
1
;
this
.
openConnection
();
this
.
setTimeout
(
this
.
openConnection
.
bind
(
this
),
randomizedTimeout
);
}
exponentialTimeout
()
{
...
...
This diff is collapsed.
Click to expand it.
src/playground/render-gui.jsx
+
5
−
0
View file @
2b92ff4e
...
...
@@ -31,6 +31,11 @@ export default appTarget => {
if
(
process
.
env
.
NODE_ENV
===
'
production
'
&&
typeof
window
===
'
object
'
)
{
// Warn before navigating away
window
.
onbeforeunload
=
()
=>
true
;
}
else
{
window
.
onerror
=
e
=>
{
alert
(
'
Uncaught error occurred–check the console
'
);
// eslint-disable-line
throw
e
;
};
}
ReactDOM
.
render
(
...
...
This diff is collapsed.
Click to expand it.
test/unit/util/cloud-provider.test.js
+
11
−
16
View file @
2b92ff4e
...
...
@@ -103,50 +103,45 @@ describe('CloudProvider', () => {
expect
(
vmIOData
[
1
].
varCreate
.
name
).
toEqual
(
'
name2
'
);
});
test
(
'
connecting sets connnection attempts back to
1
'
,
()
=>
{
test
(
'
connecting sets connnection attempts back to
0
'
,
()
=>
{
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
0
);
cloudProvider
.
connectionAttempts
=
10
;
cloudProvider
.
connection
.
_open
();
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
1
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
0
);
});
test
(
'
disconnect waits for a period equal to 2^k-1 before trying again
'
,
()
=>
{
websocketConstructorCount
=
1
;
// This is global, so set it back to
1
to start
websocketConstructorCount
=
0
;
// This is global, so set it back to
0
to start
// Connection attempts should still be 0 because connection hasn't opened yet
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
0
);
cloudProvider
.
connection
.
_open
(
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
1
*
1000
);
// 2^1 - 1
expect
(
websocketConstructorCount
).
toBe
(
1
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
1
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
1
*
1000
);
// 2^
1
- 1
expect
(
timeout
).
toEqual
(
3
*
1000
);
// 2^
2
- 1
expect
(
websocketConstructorCount
).
toBe
(
2
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
2
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
3
*
1000
);
// 2^
2
- 1
expect
(
timeout
).
toEqual
(
7
*
1000
);
// 2^
3
- 1
expect
(
websocketConstructorCount
).
toBe
(
3
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
3
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
7
*
1000
);
// 2^
3
- 1
expect
(
timeout
).
toEqual
(
15
*
1000
);
// 2^
4
- 1
expect
(
websocketConstructorCount
).
toBe
(
4
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
4
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
1
5
*
1000
);
// 2^
4
- 1
expect
(
timeout
).
toEqual
(
3
1
*
1000
);
// 2^
5
- 1
expect
(
websocketConstructorCount
).
toBe
(
5
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
5
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
31
*
1000
);
// 2^5 - 1
expect
(
timeout
).
toEqual
(
31
*
1000
);
//
maxed out at
2^5 - 1
expect
(
websocketConstructorCount
).
toBe
(
6
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
6
);
cloudProvider
.
connection
.
close
();
expect
(
timeout
).
toEqual
(
31
*
1000
);
// maxed out at 2^5 - 1
expect
(
websocketConstructorCount
).
toBe
(
7
);
expect
(
cloudProvider
.
connectionAttempts
).
toBe
(
7
);
});
test
(
'
exponentialTimeout caps connection attempt number
'
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment