activerecord-cockroachdb-adapter icon indicating copy to clipboard operation
activerecord-cockroachdb-adapter copied to clipboard

[ActiveRecord 5.2 Test Failure] test/cases/adapters/postgresql/numbers_test.rb

Open alimi opened this issue 5 years ago • 1 comments
trafficstars

Failure:
PostgresqlNumberTest#test_values [/Users/alimi/repos/rails/activerecord/test/cases/adapters/postgresql/numbers_test.rb:35]:
Expected: Infinity
  Actual: 0.0


bin/rails test Users/alimi/repos/rails/activerecord/test/cases/adapters/postgresql/numbers_test.rb:25

See the Contributing Guide for instructions on running tests.

If the test isn't valid against CockroachDB

  1. Add a ruby file to test/excludes that matches the name of the test class if one doesn't already exist. For example to exclude a test from ActiveRecord::AdapterTest, create test/excludes/ActiveRecord/AdapterTest.rb.
  2. Add an exclude statement to the file with the name of the test to exclude and a description. For example to exclude test_indexes from ActiveRecord::AdapterTest: https://github.com/cockroachdb/activerecord-cockroachdb-adapter/blob/c3cb637bd855b36bbf9e76b7947162054b95022e/test/excludes/ActiveRecord/AdapterTest.rb#L1
  3. Finally, if the test can run against CockroachDB with a few changes, add it to test/cases. Everything from the ActiveRecord test suite will be available, so a lot of the excluded test can be copied over. Namespace the test under the CockroachDB module to avoid name collisions. See test/cases/adapter_test.rb for an example.

See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48.

alimi avatar Apr 17 '20 17:04 alimi

Per #124, the following assertion fails:

assert_equal ::Float::INFINITY, second.double

Failure:
PostgresqlNumberTest#test_values [/Users/alimi/repos/rails/activerecord/test/cases/adapters/postgresql/numbers_test.rb:35]:
Expected: Infinity
  Actual: 0.0

This test fails specifically because Infinity is being cast to 0.0 when inserted into the database as a double-precision Float. Interestingly, -Infinity is handled correctly.

Calling the following in an interactive debugging session suggests that the issue may not lie with Active Record:

$ second.attributes_before_type_cast
{"id"=>2, "single"=>-Infinity, "double"=>0.0}

Both PG and CockroachDB use the IEEE 754 standard for handling special cases Infinity and -Infinity.

marlabrizel avatar May 01 '20 19:05 marlabrizel