Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
7ff48b7c
Commit
7ff48b7c
authored
1 year ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Add an upload spam test
parent
83c717d3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/templates/mmr.config.yaml
+3
-1
3 additions, 1 deletion
test/templates/mmr.config.yaml
test/upload_suite_test.go
+79
-0
79 additions, 0 deletions
test/upload_suite_test.go
with
82 additions
and
1 deletion
test/templates/mmr.config.yaml
+
3
−
1
View file @
7ff48b7c
...
@@ -37,4 +37,6 @@ datastores:
...
@@ -37,4 +37,6 @@ datastores:
bucketName
:
"
mybucket"
bucketName
:
"
mybucket"
accessKeyId
:
"
mykey"
accessKeyId
:
"
mykey"
accessSecret
:
"
mysecret"
accessSecret
:
"
mysecret"
ssl
:
false
ssl
:
false
\ No newline at end of file
rateLimit
:
enabled
:
false
# we've got tests which intentionally spam
This diff is collapsed.
Click to expand it.
test/upload_suite_test.go
+
79
−
0
View file @
7ff48b7c
...
@@ -2,8 +2,11 @@ package test
...
@@ -2,8 +2,11 @@ package test
import
(
import
(
"fmt"
"fmt"
"io"
"log"
"log"
"math/rand"
"net/http"
"net/http"
"sync"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
...
@@ -171,6 +174,82 @@ func (s *UploadTestSuite) TestUploadDeduplicationDifferentUser() {
...
@@ -171,6 +174,82 @@ func (s *UploadTestSuite) TestUploadDeduplicationDifferentUser() {
assert
.
Equal
(
t
,
record1
.
Location
,
record2
.
Location
)
assert
.
Equal
(
t
,
record1
.
Location
,
record2
.
Location
)
}
}
func
(
s
*
UploadTestSuite
)
TestUploadSpam
()
{
t
:=
s
.
T
()
const
concurrentUploads
=
100
// Clients are for the same user/server, but using different MMR machines
client1
:=
s
.
deps
.
Homeservers
[
0
]
.
UnprivilegedUsers
[
0
]
.
WithCsUrl
(
s
.
deps
.
Machines
[
0
]
.
HttpUrl
)
client2
:=
s
.
deps
.
Homeservers
[
0
]
.
UnprivilegedUsers
[
0
]
.
WithCsUrl
(
s
.
deps
.
Machines
[
1
]
.
HttpUrl
)
assert
.
Equal
(
t
,
client1
.
ServerName
,
client2
.
ServerName
)
// Create the image streams first (so we don't accidentally hit slowdowns during upload)
images
:=
make
([]
io
.
Reader
,
concurrentUploads
)
contentTypes
:=
make
([]
string
,
concurrentUploads
)
for
i
:=
0
;
i
<
concurrentUploads
;
i
++
{
c
,
img
,
err
:=
test_internals
.
MakeTestImage
(
128
,
128
)
assert
.
NoError
(
t
,
err
)
images
[
i
]
=
img
contentTypes
[
i
]
=
c
}
// Start all the uploads concurrently, and wait for them to complete
waiter
:=
new
(
sync
.
WaitGroup
)
waiter
.
Add
(
1
)
uploadWaiter
:=
new
(
sync
.
WaitGroup
)
mediaIds
:=
new
(
sync
.
Map
)
for
i
:=
0
;
i
<
concurrentUploads
;
i
++
{
go
func
(
j
int
)
{
uploadWaiter
.
Add
(
1
)
defer
uploadWaiter
.
Done
()
img
:=
images
[
j
]
contentType
:=
contentTypes
[
j
]
client
:=
client1
if
rand
.
Float32
()
<
0.5
{
client
=
client2
}
waiter
.
Wait
()
// We use random file names to guarantee different media IDs at a minimum
rstr
,
err
:=
util
.
GenerateRandomString
(
64
)
assert
.
NoError
(
t
,
err
)
res
,
err
:=
client
.
Upload
(
"image"
+
rstr
+
util
.
ExtensionForContentType
(
contentType
),
contentType
,
img
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEmpty
(
t
,
res
.
MxcUri
)
origin
,
mediaId
,
err
:=
util
.
SplitMxc
(
res
.
MxcUri
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
client
.
ServerName
,
origin
)
assert
.
NotEmpty
(
t
,
mediaId
)
mediaIds
.
Store
(
mediaId
,
true
)
}(
i
)
}
waiter
.
Done
()
uploadWaiter
.
Wait
()
// Prepare to check that only one copy of the file was uploaded each time
mediaDb
:=
database
.
GetInstance
()
.
Media
.
Prepare
(
rcontext
.
Initial
())
realMediaIds
:=
make
([]
string
,
0
)
mediaIds
.
Range
(
func
(
key
any
,
value
any
)
bool
{
realMediaIds
=
append
(
realMediaIds
,
key
.
(
string
))
return
true
})
assert
.
Greater
(
t
,
len
(
realMediaIds
),
0
)
records
,
err
:=
mediaDb
.
GetByIds
(
client1
.
ServerName
,
realMediaIds
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
records
)
assert
.
Len
(
t
,
records
,
len
(
realMediaIds
))
// Actually do the comparison
dsId
:=
records
[
0
]
.
DatastoreId
dsLocation
:=
records
[
0
]
.
Location
for
_
,
r
:=
range
records
{
assert
.
Equal
(
t
,
dsId
,
r
.
DatastoreId
)
assert
.
Equal
(
t
,
dsLocation
,
r
.
Location
)
}
}
func
TestUploadTestSuite
(
t
*
testing
.
T
)
{
func
TestUploadTestSuite
(
t
*
testing
.
T
)
{
suite
.
Run
(
t
,
new
(
UploadTestSuite
))
suite
.
Run
(
t
,
new
(
UploadTestSuite
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment