Skip to content

Commit

Permalink
changes to gridfs test, bumping version to 0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
samsamros committed Jan 14, 2024
1 parent 5d7c61c commit 7914bf8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion anonimongo.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.7.0"
version = "0.7.2"
author = "Rahmatullah"
description = "Anonimongo - Another pure Nim Mongo driver"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/anonimongo/dbops/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const
drivername = "anonimongo"
description = "nim mongo driver"
when not defined(anostreamable):
const anonimongoVersion* = "0.7.0"
const anonimongoVersion* = "0.7.2"
else:
const anonimongoVersion* = "0.7.0-stream"
const anonimongoVersion* = "0.7.2-stream"

proc handshake(m: Mongo[AsyncSocket], isMaster: bool, s: AsyncSocket, db: string, id: int32,
appname = "Anonimongo client apps"):Future[ReplyFormat] {.multisock.} =
Expand Down
4 changes: 2 additions & 2 deletions src/anonimongo/gridfs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ proc uploadFile*(g: GridFS[AsyncSocket], f: AsyncFile, filename = "", chunk = 0'
let capsize = 16.megabytes
var insertops = newseq[Future[WriteResult]]()
var chunks = newseq[BsonDocument]()
for _ in countup(0, int(fsize-1), chunksize):
for _ in countup(0, int(fsize-1), chunkSize):
var chunk = bson({
"files_id": foid,
"n": chunkn
})
let data = waitfor f.read(chunksize) # to make it work regardless sync/async because asyncfile
let data = waitfor f.read(chunkSize) # to make it work regardless sync/async because asyncfile
chunk["data"] = bsonBinary data
let newcurr = curread + data.len
if newcurr >= capsize:
Expand Down
43 changes: 24 additions & 19 deletions tests/test_gridfs_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ if filename != "" and saveas != "":
test "Create default bucket":
require db != nil
when anoSocketSync:
grid = db.createBucket(chunkSize = 1.megabytes.int32)
grid = db.createBucket(chunkSize = 131072)
else:
grid = waitfor db.createBucket(chunkSize = 1.megabytes.int32)
grid = waitfor db.createBucket(chunkSize = 131072)
require grid != nil

test "Upload file":
Expand Down Expand Up @@ -106,37 +106,42 @@ if filename != "" and saveas != "":
var gf = grid.getStream(bson({filename: dwfile}), buffered = true)
else:
var gf = waitfor grid.getStream(bson({filename: dwfile}), buffered = true)
check f.getFileSize == gf.fileSize
check f.getFilePos == gf.getPosition
doassert f.getFileSize == gf.fileSize
doassert f.getFilePos == gf.getPosition


let threekb = 3.kilobytes
when anoSocketSync:
var binread = gf.read(threekb)
else:
var binread = waitfor gf.read(threekb)
var bufread = waitfor f.read(threekb)
check bufread == binread
check f.getFilePos == gf.getPosition
doassert bufread == binread
doassert f.getFilePos == gf.getPosition


let fivemb = 5.megabytes
f.setFilePos fivemb
let kbStream = 131072 #changed
f.setFilePos kbStream
when anoSocketSync:
gf.setPosition fivemb
gf.setPosition kbStream
else:
waitfor gf.setPosition fivemb
check f.getFilePos == gf.getPosition

waitfor gf.setPosition kbStream
doassert f.getFilePos == gf.getPosition


when anoSocketSync:
binread = gf.read(fivemb)
#it can't be fivemb because of the buffer limit in tests
binread = gf.read(kbStream)
else:
binread = waitfor gf.read(fivemb)
bufread = waitfor f.read(fivemb)
check bufread.len == binread.len
check bufread == binread
check f.getFilePos == gf.getPosition
binread = waitfor gf.read(kbStream)
bufread = waitfor f.read(kbStream)
doassert bufread.len == binread.len
doassert bufread == binread
doassert f.getFilePos == gf.getPosition

close f
close gf


test "Gridstream read chunked size":
let chunkfile = "gs_chunks.mkv"
Expand Down Expand Up @@ -246,4 +251,4 @@ if filename != "" and saveas != "":
close mongo
if runlocal:
if mongorun != nil and mongorun.running: kill mongorun
close mongorun
close mongorun

0 comments on commit 7914bf8

Please sign in to comment.