Skip to content

GODRIVER-2872 Fix failing "TestClientSideEncryptionProse" test. #1359

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

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions mongo/integration/client_side_encryption_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,6 @@ func TestClientSideEncryptionProse(t *testing.T) {
}
})
mt.Run("4. bson size limits", func(mt *mtest.T) {
// TODO(GODRIVER-2872): Fix and unskip this test case.
mt.Skip("Test fails frequently, skipping. See GODRIVER-2872")

kmsProviders := map[string]map[string]interface{}{
"local": {
"key": localMasterKey,
Expand Down
17 changes: 12 additions & 5 deletions x/mongo/driver/mongocrypt/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

package mongocrypt

// #include <mongocrypt.h>
/*
#include <stdlib.h>
#include <mongocrypt.h>
*/
import "C"
import (
"unsafe"
)

// binary is a wrapper type around a mongocrypt_binary_t*
type binary struct {
p *C.uint8_t
wrapped *C.mongocrypt_binary_t
}

Expand All @@ -33,11 +37,11 @@ func newBinaryFromBytes(data []byte) *binary {
return newBinary()
}

// We don't need C.CBytes here because data cannot go out of scope. Any mongocrypt function that takes a
// mongocrypt_binary_t will make a copy of the data so the data can be garbage collected after calling.
addr := (*C.uint8_t)(unsafe.Pointer(&data[0])) // uint8_t*
dataLen := C.uint32_t(len(data)) // uint32_t
// TODO: Consider using runtime.Pinner to replace the C.CBytes after using go1.21.0.
addr := (*C.uint8_t)(C.CBytes(data)) // uint8_t*
dataLen := C.uint32_t(len(data)) // uint32_t
return &binary{
p: addr,
wrapped: C.mongocrypt_binary_new_from_data(addr, dataLen),
}
}
Expand All @@ -52,5 +56,8 @@ func (b *binary) toBytes() []byte {

// close cleans up any resources associated with the given binary instance.
func (b *binary) close() {
if b.p != nil {
C.free(unsafe.Pointer(b.p))
}
C.mongocrypt_binary_destroy(b.wrapped)
}