Skip to content

Commit 2aa3c5a

Browse files
authored
Another float8 to prevent query-crash (#306)
Added a test to test the UpdatePeerGeo function. In the existing tests the lobby peers' geo comes from direct SQL INSERT.
1 parent 8bd93fc commit 2aa3c5a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

features/latency2.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ Feature: Geo-based latency2 estimates
44
Given the "signaling" backend is running
55
And the "testproxy" backend is running
66

7+
Scenario: latency2 is computed using peer geo persisted on connect
8+
Given "red" is connected as "1u8fw4aph5ypt" with lat,lon as 10,20 and ready for game "323e4567-e89b-12d3-a456-426614174000"
9+
And "yellow" is connected as "h5yzwyizlwao" with lat,lon as 30,40 and ready for game "323e4567-e89b-12d3-a456-426614174000"
10+
And "red,yellow" are joined in a public lobby
11+
And "blue" is connected as "3t3cfgcqup9e" with lat,lon as 50,60 and ready for game "323e4567-e89b-12d3-a456-426614174000"
12+
13+
When "blue" requests lobbies with:
14+
"""json
15+
{}
16+
"""
17+
18+
Then "blue" should have received only these lobbies:
19+
| code | latency2 |
20+
| 19yrzmetd2bn7 | 69 |
21+
722
Scenario: latency2 is computed from requester to lobby peers
823
Given these lobbies exist:
924
| code | game | peers | public |

internal/signaling/stores/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (s *PostgresStore) UpdatePeerGeo(ctx context.Context, peerID string, lat, l
464464
UPDATE peers
465465
SET
466466
geo = CASE
467-
WHEN $1 IS NOT NULL AND $2 IS NOT NULL THEN ll_to_earth($1::float8, $2::float8)
467+
WHEN $1::float8 IS NOT NULL AND $2::float8 IS NOT NULL THEN ll_to_earth($1::float8, $2::float8)
468468
ELSE NULL
469469
END,
470470
updated_at = $3

0 commit comments

Comments
 (0)