You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
989 B

  1. package query_test
  2. import (
  3. "testing"
  4. "github.com/tendermint/tendermint/abci/types"
  5. "github.com/tendermint/tendermint/internal/pubsub/query"
  6. )
  7. const testQuery = `tm.events.type='NewBlock' AND abci.account.name='Igor'`
  8. var testEvents = []types.Event{
  9. {
  10. Type: "tm.events",
  11. Attributes: []types.EventAttribute{{
  12. Key: "index",
  13. Value: "25",
  14. }, {
  15. Key: "type",
  16. Value: "NewBlock",
  17. }},
  18. },
  19. {
  20. Type: "abci.account",
  21. Attributes: []types.EventAttribute{{
  22. Key: "name",
  23. Value: "Anya",
  24. }, {
  25. Key: "name",
  26. Value: "Igor",
  27. }},
  28. },
  29. }
  30. func BenchmarkParseCustom(b *testing.B) {
  31. for i := 0; i < b.N; i++ {
  32. _, err := query.New(testQuery)
  33. if err != nil {
  34. b.Fatal(err)
  35. }
  36. }
  37. }
  38. func BenchmarkMatchCustom(b *testing.B) {
  39. q, err := query.New(testQuery)
  40. if err != nil {
  41. b.Fatal(err)
  42. }
  43. b.ResetTimer()
  44. for i := 0; i < b.N; i++ {
  45. ok, err := q.Matches(testEvents)
  46. if err != nil {
  47. b.Fatal(err)
  48. } else if !ok {
  49. b.Error("no match")
  50. }
  51. }
  52. }