Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ConfigTests tests #85

Closed
wants to merge 1 commit into from
Closed

Conversation

Gor027
Copy link
Contributor

@Gor027 Gor027 commented Oct 13, 2022

Added implementation for functions in testing.cpp used in ConfigTests tests:

  • get_connect_timeout_from_cluster
  • get_port_from_cluster
  • get_contact_points_from_cluster

To avoid generating bindings for functions that are directly under namespaces and may return objects of custom types, the testing_utils header is added as a median between the Rust implementation of those functions and the testing.hpp header.

Added ConfigTests tests to GitHub Actions for Cassandra and ScyllaDB.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have enabled appropriate tests in .github/workflows/build.yml in gtest_filter.
  • I have enabled appropriate tests in .github/workflows/cassandra.yml in gtest_filter.

cluster: *mut CassCluster,
contact_points: *mut *const c_char,
contact_points_length: *mut size_t,
contact_points_boxed: *mut *const String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably doesn't matter, but maybe this should be *mut *mut? We use it as *mut String when freeing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that does not have an effect on the generated code and rather is a question of documenting intent.

Comment on lines 36 to 49
fn prepare_testing_bindings(out_path: &Path) {
let testing_bindings = bindgen::Builder::default()
.header("extern/testing_utils.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.layout_tests(true)
.generate_comments(false)
.generate()
.expect("Unable to generate bindings");

testing_bindings
.write_to_file(out_path.join("testing_bindings.rs"))
.expect("Couldn't write bindings!");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you generating those bindings? It doesn't look like your'e using them anywhere

Comment on lines +1 to +26
#include "testing_utils.h"
#include <stdexcept>

CASS_EXPORT CassConsistency testing_get_consistency(const CassStatement* statement) {
throw std::runtime_error("UNIMPLEMENTED testing_get_consistency\n");
}

CASS_EXPORT CassConsistency testing_get_serial_consistency(const CassStatement* statement) {
throw std::runtime_error("UNIMPLEMENTED testing_get_serial_consistency\n");
}

CASS_EXPORT cass_uint64_t testing_get_request_timeout_ms(const CassStatement* statement) {
throw std::runtime_error("UNIMPLEMENTED testing_get_request_timeout_ms\n");
}

CASS_EXPORT const CassRetryPolicy* testing_get_retry_policy(const CassStatement* statement) {
throw std::runtime_error("UNIMPLEMENTED testing_get_retry_policy\n");
}

CASS_EXPORT const char* testing_get_server_name(CassFuture* future) {
throw std::runtime_error("UNIMPLEMENTED testing_get_server_name\n");
}

CASS_EXPORT void testing_set_record_attempted_hosts(CassStatement* statement, cass_bool_t enable) {
throw std::runtime_error("UNIMPLEMENTED testing_set_record_attempted_hosts\n");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those implementations required? Can't you just remove them from testing_utils.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can safely remove them, but I guess this way it will be much easier to find which testing functions are yet to be implemented.

Comment on lines +1 to +34
#ifndef CPPDRIVERV2_TESTING_UTILS_H
#define CPPDRIVERV2_TESTING_UTILS_H

#include "cassandra.h"

extern "C" {
CASS_EXPORT cass_uint16_t testing_get_connect_timeout_from_cluster(CassCluster* cluster);

CASS_EXPORT cass_int32_t testing_get_port_from_cluster(CassCluster* cluster);

CASS_EXPORT void
testing_get_contact_points_from_cluster(
CassCluster* cluster,
const char** contact_points,
size_t* contact_points_length,
void** contact_points_boxed
);

CASS_EXPORT void testing_free_contact_points_string(void* box);

CASS_EXPORT CassConsistency testing_get_consistency(const CassStatement* statement);

CASS_EXPORT CassConsistency testing_get_serial_consistency(const CassStatement* statement);

CASS_EXPORT cass_uint64_t testing_get_request_timeout_ms(const CassStatement* statement);

CASS_EXPORT const CassRetryPolicy* testing_get_retry_policy(const CassStatement* statement);

CASS_EXPORT const char* testing_get_server_name(CassFuture* future);

CASS_EXPORT void testing_set_record_attempted_hosts(CassStatement* statement, cass_bool_t enable);
}

#endif //CPPDRIVERV2_TESTING_UTILS_H
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is present twice for some reason, with a slight modification. Do we need it twice in our repository?

Also, if I'm understanding this correctly, those are signatures for Rust functions that are used in implementation of testing.hpp. If that's the case then:

  1. Name should be different than testing_utils.h - something like testing_rust_impls.h maybe?
  2. This file should not be written by hand, but rather generated - cbindgen is a tool to do that

Added implementation for functions in `testing.cpp` used in
`ConfigTests` tests:
 * get_connect_timeout_from_cluster
 * get_port_from_cluster
 * get_contact_points_from_cluster

To avoid generating bindings for functions that are directly under
namespaces and may return objects of custom types, `testing_utils`
header is added as median between the Rust implementation of those
functions and the `testing.hpp` header.

Added `ConfigTests` tests to GitHub Actions for Cassandra and ScyllaDB.
@muzarski
Copy link
Collaborator

muzarski commented Sep 9, 2024

Closing in favor of #163

@muzarski muzarski closed this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants