From ca52a1dea6c482df8f7d189dd84e302dfa4f9179 Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Wed, 21 Aug 2024 09:15:42 +0100 Subject: [PATCH] spec: Don't expect integers to round-trip through msg.extras Internally, we store msg.extras in a protobuf.Struct which stores a JSON number in a double field: https://github.com/protocolbuffers/protobuf/blob/5cbf13bc9ab0f883bcb664241f6be8d962915569/src/google/protobuf/struct.proto#L56-L78 This means that when a connection is using binary encoding (i.e. msgpack), any numbers in msg.extras are encoded as floats even if the inbound message encoded the number as an int type, so the inbound and outbound representations are not guaranteed to be the same, although the semantic numeric value will be the same. This commit handles this nuance by not expecting an integer to come back as an integer in msg.extras, but expecting a float to instead. Signed-off-by: Lewis Marshall --- spec/acceptance/realtime/message_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/realtime/message_spec.rb b/spec/acceptance/realtime/message_spec.rb index e5eec8e7..b218a8e1 100644 --- a/spec/acceptance/realtime/message_spec.rb +++ b/spec/acceptance/realtime/message_spec.rb @@ -173,7 +173,7 @@ def publish_and_check_extras(extras) end context 'JSON Array' do - let(:data) { { 'push' => { 'data' => { 'key' => [ true, false, 55, nil, 'string', { 'Hash' => true }, ['array'] ] } } } } + let(:data) { { 'push' => { 'data' => { 'key' => [ true, false, 55.1, nil, 'string', { 'Hash' => true }, ['array'] ] } } } } it 'is encoded and decoded to the same Array' do publish_and_check_extras data