 #			test.done()
 
 
-exports.generateSessId =
-	testNoErrors: (test) ->
-		_createSalt = users.createSalt
-		i = 0
-		users.createSalt = (len) ->
-			'someid' + (++i)
-
-		async.series [
-			(callback) ->
-				mg.migrate conn, { tables: ['permission_kind', 'uniusers'] }, callback
-			(callback) ->
-				conn.query "INSERT INTO uniusers (sessid) VALUES ('someid1')", callback
-			(callback) ->
-				conn.query "INSERT INTO uniusers (sessid) VALUES ('someid2')", callback
-			(callback) ->
-				users.generateSessId conn, 16, callback
-			(callback) ->
-				conn.query 'DROP TABLE uniusers', [], callback
-		],
-		(error, result) ->
-			users.createSalt = _createSalt
-			test.ifError error
-			test.strictEqual result[3], 'someid3', 'sessid should be unique'
-			test.done()
-
-	testErrors: (test) ->
-		users.generateSessId conn, 16, (error, result) ->
-			test.ok error, 'should return error without table'
-			test.done()
+exports.generateSessId = (test) ->
+	_createSalt = users.createSalt
+	i = 0
+	users.createSalt = (len) ->
+		'someid' + (++i)
+
+	clearTables 'uniusers'
+	query "INSERT INTO uniusers (sessid) VALUES ('someid1')"
+	query "INSERT INTO uniusers (sessid) VALUES ('someid2')"
+	sessid = users.generateSessId.sync users, conn, 16
+
+	users.createSalt = _createSalt
+	test.strictEqual sessid, 'someid3', 'sessid should be unique'
+	test.done()
 
 
 exports.idBySession =
 	testNoErrors: (test) ->
-		async.series [
-			(callback) ->
-				mg.migrate conn, { tables: ['permission_kind', 'uniusers'] }, callback
-			(callback) ->
-				conn.query "INSERT INTO uniusers ( id, sessid ) VALUES ( 3, 'someid' )", callback
-			(callback) ->
-				users.idBySession conn, "someid", callback
-		],
-		(error, result) ->
-			test.ifError error
-			test.strictEqual result[2], 3, 'should return correct user id'
-			test.done()
+		clearTables 'uniusers'
+		query "INSERT INTO uniusers ( id, sessid ) VALUES ( 3, 'someid' )"
+		userid = users.idBySession.sync null, conn, "someid"
+		test.strictEqual userid, 3, 'should return correct user id'
+		test.done()
 
 	testWrongSessid: (test) ->
-		async.series [
-			(callback) ->
-				mg.migrate conn, { tables: ['permission_kind', 'uniusers'] }, callback
-			(callback) ->
-				users.idBySession conn, 'someid', callback
-			(callback) ->
-				conn.query 'DROP TABLE uniusers', [], callback
-		],
-		(error, result) ->
-			test.ok error, 'should return error on wrong sessid'
-			test.done()
-
-	testQueryError: (test) ->
-		users.idBySession conn, 'someid', (error, result) ->
-			test.ok error, 'should return error without table'
-			test.done()
-
-
-exports.closeSession =
-	testNoErrors: (test) ->
-		async.series [
-			(callback) -> #0
-				mg.migrate conn, { tables: ['permission_kind', 'uniusers'] }, callback
-			(callback) ->
-				conn.query "INSERT INTO uniusers ( sessid, sess_time ) VALUES ( 'someid', NOW() )", [], callback
-			(callback) ->
-				users.closeSession conn, 'someid', callback
-			(callback) ->
-				users.sessionInfoRefreshing conn, 'someid', 3600, callback
-			(callback) ->
-				users.closeSession conn, undefined, callback
-		],
-		(error, result) ->
-			test.ifError error
-			test.strictEqual result[3].sessionIsActive, false, 'session should have expired'
-			test.strictEqual result[4], 'Not closing: empty sessid', 'should not fail with empty sessid'
-			test.done()
-
-	testErrors: (test) ->
-		users.closeSession conn, 'someid', (error, result) ->
-			test.ok error, 'should return error without table'
-			test.done()
+		clearTables 'uniusers'
+		test.throws(
+			-> users.idBySession.sync null, conn, 'someid'
+			Error
+			'should return error on wrong sessid'
+		)
+		test.done()
+
+
+exports.closeSession = (test) ->
+	clearTables 'uniusers'
+	query "INSERT INTO uniusers ( sessid, sess_time ) VALUES ( 'someid', NOW() )"
+	users.closeSession.sync null, conn, 'someid'
+	refr = users.sessionInfoRefreshing.sync null, conn, 'someid', 3600
+	warn1 = users.closeSession.sync null, conn, undefined
+	
+	test.strictEqual refr.sessionIsActive, false, 'session should have expired'
+	test.strictEqual warn1, 'Not closing: empty sessid', 'should not fail with empty sessid'
+	test.done()
 
 
 exports.createSalt = (test) ->

			userid: 8
		}, 'session should be active if not expired and user data should be returned'
		
		timeAfter = new Date(queryOne('SELECT sess_time FROM uniusers').sess_time)
		test.ok timeBefore < timeAfter, 'should update session timestamp'
		
		res = users.sessionInfoRefreshing.sync null, conn, undefined, 7200, false

		
		query "UPDATE uniusers SET sessid = 'someid'"
		
		timeBefore = new Date(query.val 'SELECT sess_time FROM uniusers')
		
		res = users.sessionInfoRefreshing.sync null, conn, 'someid', 7200, false
		test.deepEqual res, {
