github.com/weaviate/weaviate@v1.24.6/test/acceptance/multi_node/bm25_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package multi_node
    13  
    14  import (
    15  	"context"
    16  	"fmt"
    17  	"testing"
    18  	"time"
    19  
    20  	"github.com/stretchr/testify/require"
    21  	"github.com/weaviate/weaviate/test/docker"
    22  	"github.com/weaviate/weaviate/test/helper"
    23  	graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
    24  	"github.com/weaviate/weaviate/test/helper/sample-schema/articles"
    25  )
    26  
    27  var paragraphs = []string{
    28  	"Some random text",
    29  	"Other text",
    30  	"completely unrelated",
    31  	"this has nothing to do with the rest",
    32  }
    33  
    34  func TestBm25MultiNode(t *testing.T) {
    35  	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
    36  	defer cancel()
    37  	for i := 0; i < 5; i++ {
    38  		t.Run(fmt.Sprintf("iteration: %v", i), func(t *testing.T) {
    39  			runBM25MultinodeTest(t, ctx)
    40  		})
    41  	}
    42  }
    43  
    44  func runBM25MultinodeTest(t *testing.T, ctx context.Context) {
    45  	compose, err := docker.New().
    46  		WithWeaviateCluster().
    47  		Start(ctx)
    48  	require.NoError(t, err)
    49  	defer func() {
    50  		if err := compose.Terminate(ctx); err != nil {
    51  			t.Fatalf("failed to terminate test containers: %s", err.Error())
    52  		}
    53  	}()
    54  
    55  	helper.SetupClient(compose.GetWeaviate().URI())
    56  	paragraphClass := articles.ParagraphsClass()
    57  	helper.CreateClass(t, paragraphClass)
    58  	for _, par := range paragraphs {
    59  		obj := articles.NewParagraph().
    60  			WithContents(par).
    61  			Object()
    62  		helper.CreateObject(t, obj)
    63  	}
    64  
    65  	query := `
    66  		{
    67  			Get {
    68  				Paragraph (bm25:{query:"random"}){
    69  					contents
    70  				}
    71  			}
    72  		}
    73  		`
    74  	result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
    75  	resParagraph := result.Get("Get", "Paragraph").AsSlice()
    76  	require.Equal(t, resParagraph[0].(map[string]interface{})["contents"], paragraphs[0])
    77  }