def test_1_new_address(self): '''new address for Zac''' max_duration = 0.01 avg_duration = 0.002 round = 5000 Zac.create() account_table_file = '/home/%s/.metaverse/mainnet/account_table' % common.get_username( ) try: origin_payload_size = database.get_payload_size(account_table_file) durations = [] for i in range(round): duration, ret = common.duration_call(mvs_rpc.new_address, Zac.name, Zac.password) self.assertEqual(ret[0], 0, "mvs_rpc.new_address failed!") self.assertLess(duration, max_duration) durations.append(duration) self.assertLess(sum(durations), avg_duration * round) current_payload_size = database.get_payload_size( account_table_file) # each simple account record size < 300 self.assertGreater( 300 * round, current_payload_size - origin_payload_size, "each account record size shall be less than 300.") finally: Zac.delete()
def extra_update(self, validated_data, model_name=None, name=None): username = get_username(self.context['request'].user) # 转换时间为utc时间 now = timezone.now().astimezone(pytz.utc).strftime("%Y-%m-%d %H:%M:%S") # info:这一步的目的为了不改变传入的数据结构 update_data = dict([(key, value) for key, value in validated_data.items()]) update_data.update({'updater': username, 'update_time': now}) logger.info(u'用户%s更新名称是%s的%s成功' % (username, name, model_name)) return update_data
def extra_create(self, validated_data, model_name=None, name=None): username = get_username(self.context['request'].user) # 转换时间为utc时间 now = timezone.now().astimezone(pytz.utc).strftime("%Y-%m-%d %H:%M:%S") save_data = dict([(key, value) for key, value in validated_data.items()]) save_data.update({ 'founder': username, 'updater': username, 'create_time': now, 'update_time': now }) logger.info(u'用户%s创建名称是%s的%s成功' % (username, name, model_name)) return save_data
def test_0_new_account(self): '''create new account * 5000''' account_table_file = '/home/%s/.metaverse/mainnet/account_table' % common.get_username( ) origin_payload_size = database.get_payload_size(account_table_file) batch_amount = 5000 lastwords = [] for i in range(batch_amount): ec, message = mvs_rpc.new_account("Account_%s" % i, "123456") self.assertEqual(ec, 0, message) lastwords.append(message[-1]) try: current_payload_size = database.get_payload_size( account_table_file) # each simple account record size < 300, but when getnew address, the account record will be create twice, so 600 is the reasonable record size. self.assertGreater( 600 * batch_amount, current_payload_size - origin_payload_size, "each account record size shall be less than 600.") finally: for i in range(batch_amount): ec, message = mvs_rpc.delete_account("Account_%s" % i, "123456", lastwords[i]) self.assertEqual(ec, 0, message)