Open tee0zed opened 6 months ago
Yeah definetely test env, reproduced in RAILS_ENV=test rails c
for testing clickhouse there is a better approach
module TestClickhouseHelper
class InsertCounter
include Singleton
attr_reader :data
def initialize
reset
end
def reset
@data = {}
end
def qty
@data.values.sum
end
def active_klasses
@data.select { |_, qty| qty.positive? }.keys.map(&:constantize)
end
def increment(klass)
@data[klass.to_s] ||= 0
@data[klass.to_s] += 1
end
end
module ExampleGroups
# Do not wrap clickhouse connections in transactions because it does not support transactions.
# @see ActiveRecord::TestFixtures#enlist_fixture_connections
def enlist_fixture_connections
connections = super
connections.reject { |conn| conn.is_a?(ActiveRecord::ConnectionAdapters::ClickhouseAdapter) }
end
end
end
ActiveRecord::TestFixtures.prepend TestClickhouseHelper::ExampleGroups
clickhouse_classes = ClickHouseRecord.descendants
clickhouse_classes.each do |klass|
klass.after_create { TestClickhouseHelper::InsertCounter.instance.increment(self.class) }
end
RSpec.configure do |config|
config.after do
# truncate clickhouse tables only if they have inserts
TestClickhouseHelper::InsertCounter.instance.active_klasses.each do |klass|
ClickHouseRecord.connection.execute("TRUNCATE TABLE #{klass.table_name}")
end
TestClickhouseHelper::InsertCounter.instance.reset
end
end
I have very cryptic one also.
In test env, using
transactional_fixtures
or not, materialized views never triggered. I don't see any connections with Rails.env and Clickhouse, but in dev i have mySummingMergeTree
table filling with MV described withTO
statement, but in test environment i have only first,MergeTree
table been filling with records, but views seems to be dead. Clickhouse logs seems legit, no errors.This is my migrations
This is how I insert records in test
This is hooks configuration that i use
I also tried to set .use_transactional_fixtures = false in base rspec config
Have you seen this before?