MCPcopy Create free account
hub / github.com/daodst/chat / TestExpireEDUs

Function TestExpireEDUs

federationapi/storage/storage_test.go:32–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestExpireEDUs(t *testing.T) {
33 var expireEDUTypes = map[string]time.Duration{
34 gomatrixserverlib.MReceipt: time.Millisecond,
35 }
36
37 ctx := context.Background()
38 test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
39 db, close := mustCreateFederationDatabase(t, dbType)
40 defer close()
41 // insert some data
42 for i := 0; i < 100; i++ {
43 receipt, err := db.StoreJSON(ctx, "{}")
44 assert.NoError(t, err)
45
46 err = db.AssociateEDUWithDestination(ctx, "localhost", receipt, gomatrixserverlib.MReceipt, expireEDUTypes)
47 assert.NoError(t, err)
48 }
49 // add data without expiry
50 receipt, err := db.StoreJSON(ctx, "{}")
51 assert.NoError(t, err)
52
53 // m.read_marker gets the default expiry of 24h, so won't be deleted further down in this test
54 err = db.AssociateEDUWithDestination(ctx, "localhost", receipt, "m.read_marker", expireEDUTypes)
55 assert.NoError(t, err)
56
57 // Delete expired EDUs
58 err = db.DeleteExpiredEDUs(ctx)
59 assert.NoError(t, err)
60
61 // verify the data is gone
62 data, err := db.GetPendingEDUs(ctx, "localhost", 100)
63 assert.NoError(t, err)
64 assert.Equal(t, 1, len(data))
65
66 // check that m.direct_to_device is never expired
67 receipt, err = db.StoreJSON(ctx, "{}")
68 assert.NoError(t, err)
69
70 err = db.AssociateEDUWithDestination(ctx, "localhost", receipt, gomatrixserverlib.MDirectToDevice, expireEDUTypes)
71 assert.NoError(t, err)
72
73 err = db.DeleteExpiredEDUs(ctx)
74 assert.NoError(t, err)
75
76 // We should get two EDUs, the m.read_marker and the m.direct_to_device
77 data, err = db.GetPendingEDUs(ctx, "localhost", 100)
78 assert.NoError(t, err)
79 assert.Equal(t, 2, len(data))
80 })
81}

Callers

nothing calls this directly

Calls 5

StoreJSONMethod · 0.65
DeleteExpiredEDUsMethod · 0.65
GetPendingEDUsMethod · 0.65

Tested by

no test coverage detected